Deduplicate and analyze sets with unique(), intersect1d(), union1d(), and setdiff1d().
`np.unique()` extracts unique sorted elements and can optionally return frequency counts. Set functions compute mathematical intersections and unions.
`np.unique(arr, return_counts=True)` is like a voting ballot tally box: it counts the distinct candidates and how many votes each candidate received.
`np.unique(arr, return_counts=True)` returns a tuple: (unique_elements, counts).
vals, counts = np.unique(arr, return_counts=True)list(set(arr)) # Destroys array typing and returns unsorted Python setnp.unique(arr) # Returns sorted ndarray`np.unique()` returns a typed ndarray and is much faster than round-tripping through Python's `set()`.
Solve the objective below using NumPy vectorized syntax
Create `a = np.array([10, 20, 30])` and `b = np.array([20, 30, 40])`, find intersection with `np.intersect1d(a, b)`, and print.
[20 30]