Set Operations
union1d, intersect1d, setdiff1d and in1d work on arrays like sets.
Example
a = np.array([1, 2, 3, 4]); b = np.array([3, 4, 5])
print(np.union1d(a, b), np.intersect1d(a, b), np.setdiff1d(a, b))
print(np.isin(a, b))Result
[1 2 3 4 5] [3 4] [1 2] [False False True True]
Exercise
Common items.
np.(a, b)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.