intersect1d¶
- intersect1d(*arrays: Any, assume_unique: bool = False, xp: ModuleType | None = None) Any[source][source]¶
- SciPy-specific replacement for
np.intersect1dwithassume_uniqueand xp.
- Parameters:
*arrays (
array_like) – Input arrays. Will be cast to a common type.assume_unique (
bool, optional) –- If True, the input arrays are assumed to be unique, which can speed up
the calculation.
xp (
array_namespace, optional) –- The array API namespace to use. If not provided, the namespace is
inferred from the arrays.
- Returns:
intersect1d – Sorted 1D array of common elements.
- Return type:
array
Notes
This function is a thin wrapper around
setdiff1dfromarray_api_extra.Examples
>>> import numpy as np >>> x = np.array([1, 2, 3, 4, 5]) >>> y = np.array([3, 4, 5, 6, 7]) >>> intersect1d(x, y) array([3, 4, 5]) >>> z = np.array([3, 4, 7, 8]) >>> intersect1d(x, y, z) array([3, 4])
- SciPy-specific replacement for