numpy.intersect1d(ar1, ar2, assume_unique=False)[source]
Find the intersection of two arrays.
Return the sorted, unique values that are in both of the input arrays.
Parameters: |
ar1, ar2 : array_like Input arrays. assume_unique : bool If True, the input arrays are both assumed to be unique, which can speed up the calculation. Default is False. |
---|---|
Returns: |
intersect1d : ndarray Sorted 1D array of common and unique elements. |
See also
numpy.lib.arraysetops
>>> np.intersect1d([1, 3, 4, 3], [3, 1, 2, 1]) array([1, 3])
To intersect more than two arrays, use functools.reduce:
>>> from functools import reduce >>> reduce(np.intersect1d, ([1, 3, 4, 3], [3, 1, 2, 1], [6, 3, 4, 2])) array([3])
© 2008–2016 NumPy Developers
Licensed under the NumPy License.
https://docs.scipy.org/doc/numpy-1.11.0/reference/generated/numpy.intersect1d.html