intersect1d

Contents

intersect1d#

class saiunit.math.intersect1d(ar1, ar2, assume_unique=False, return_indices=False, **kwargs)#

Find the intersection of two arrays.

Return the sorted, unique values that are in both of the input arrays.

Parameters:
  • ar1 (Array | ndarray | bool | number | bool | int | float | complex | saiunit.Quantity) – Input arrays. Will be flattened if not already 1D.

  • ar2 (Array | ndarray | bool | number | bool | int | float | complex | saiunit.Quantity) – Input arrays. Will be flattened if not already 1D.

  • assume_unique (bool) – If 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 (bool) – If 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.

Return type:

Array | saiunit.Quantity | tuple[Array | saiunit.Quantity, Array, Array]

Returns:

  • intersect1d (ndarray, Quantity) – 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

>>> import saiunit as u
>>> a = [1, 2, 3, 4, 5] * u.second
>>> b = [3, 4, 5, 6, 7] * u.second
>>> u.math.intersect1d(a, b)