bundles / numpy 2.4.4 / numpy / intersect1d
_ArrayFunctionDispatcher
numpy:intersect1d
Signature
def intersect1d ( ar1 , ar2 , assume_unique = False , return_indices = False ) Summary
Find the intersection of two arrays.
Extended Summary
Return the sorted, unique values that are in both of the input arrays.
Parameters
ar1, ar2: array_likeInput arrays. Will be flattened if not already 1D.
assume_unique: boolIf True, the input arrays are both assumed to be unique, which can speed up the calculation. If True but
ar1orar2are 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: ndarraySorted 1D array of common and unique elements.
comm1: ndarrayThe indices of the first occurrences of the common values in
ar1. Only provided ifreturn_indicesis True.comm2: ndarrayThe indices of the first occurrences of the common values in
ar2. Only provided ifreturn_indicesis True.
Examples
import numpy as np np.intersect1d([1, 3, 4, 3], [3, 1, 2, 1])✓
from functools import reduce reduce(np.intersect1d, ([1, 3, 4, 3], [3, 1, 2, 1], [6, 3, 4, 2]))✓
x = np.array([1, 1, 2, 3, 4]) y = np.array([2, 1, 4, 6]) xy, x_ind, y_ind = np.intersect1d(x, y, return_indices=True) x_ind, y_ind xy, x[x_ind], y[y_ind]✓
Aliases
-
numpy.intersect1d