mindspore.numpy.in1d

mindspore.numpy.in1d(ar1, ar2, invert=False)[source]

Tests whether each element of a 1-D array is also present in a second array.

Returns a boolean array the same length as ar1 that is True where an element of ar1 is in ar2 and False otherwise.

Note

Numpy argument assume_unique is not supported since the implementation does not rely on the uniqueness of the input arrays.

Parameters
  • ar1 (Union[int, float, bool, list, tuple, Tensor]) – Input array with shape (M,).

  • ar2 (Union[int, float, bool, list, tuple, Tensor]) – The values against which to test each value of ar1.

  • invert (boolean, optional) – If True, the values in the returned array are inverted (that is, False where an element of ar1 is in ar2 and True otherwise). Default is False.

Returns

Tensor, with shape (M,). The values ar1[in1d] are in ar2.

Supported Platforms:

Ascend GPU CPU

Examples

>>> test = np.array([0, 1, 2, 5, 0])
>>> states = [0, 2]
>>> mask = np.in1d(test, states)
>>> print(mask)
[ True False  True False  True]
>>> mask = np.in1d(test, states, invert=True)
>>> print(mask)
[False  True False  True False]