dpnp.isin

dpnp.isin(element, test_elements, assume_unique=False, invert=False, *, kind=None)[source]

Calculates element in test_elements, broadcasting over element only. Returns a boolean array of the same shape as element that is True where an element of element is in test_elements and False otherwise.

For full documentation refer to numpy.isin.

Parameters:
  • element ({dpnp.ndarray, usm_ndarray, scalar}) -- Input array.

  • test_elements ({dpnp.ndarray, usm_ndarray, scalar}) -- The values against which to test each value of element. This argument is flattened if it is an array.

  • assume_unique (bool, optional) --

    Ignored, as no performance benefit is gained by assuming the input arrays are unique. Included for compatibility with NumPy.

    Default: False.

  • invert (bool, optional) --

    If True, the values in the returned array are inverted, as if calculating element not in test_elements. dpnp.isin(a, b, invert=True) is equivalent to (but faster than) dpnp.invert(dpnp.isin(a, b)).

    Default: False.

  • kind ({None, "sort"}, optional) --

    Ignored, as the only algorithm implemented is "sort". Included for compatibility with NumPy.

    Default: None.

Returns:

isin -- Has the same shape as element. The values element[isin] are in test_elements.

Return type:

dpnp.ndarray of bool dtype

Examples

>>> import dpnp as np
>>> element = 2*np.arange(4).reshape((2, 2))
>>> element
array([[0, 2],
       [4, 6]])
>>> test_elements = [1, 2, 4, 8]
>>> mask = np.isin(element, test_elements)
>>> mask
array([[False,  True],
       [ True, False]])
>>> element[mask]
array([2, 4])

The indices of the matched values can be obtained with nonzero:

>>> np.nonzero(mask)
(array([0, 1]), array([1, 0]))

The test can also be inverted:

>>> mask = np.isin(element, test_elements, invert=True)
>>> mask
array([[ True, False],
       [False,  True]])
>>> element[mask]
array([0, 6])