assume_unique : boolIf True, the input arrays are both assumed to be unique, which
can speed up the calculation. If True but ar1 or ar2 are not
unique, incorrect results and out-of-bounds indices could result.
Default is False.
return_indices : boolIf True, the indices which correspond to the intersection of the two
arrays are returned. The first instance of a value is used if there are
multiple. Default is False.
Returns:
- intersect1d : ndarray
Sorted 1D array of common and unique elements.
- comm1 : ndarray
The indices of the first occurrences of the common values in ar1.
Only provided if return_indices is True.
- comm2 : ndarray
The indices of the first occurrences of the common values in ar2.
Only provided if return_indices is True.
Examples
,
4
,
2
]))
array([3])
,
y_ind
=
np
.
intersect1d
(
x
,
y
,
return_indices
=
True
)
x_ind
,
y_ind
(array([0, 2, 4]), array([1, 0, 2]))
xy
,
x
[
x_ind
],
y
[
y_ind
]
(array([1, 2, 4]), array([1, 2, 4]), array([1, 2, 4]))