mindspore.numpy.isin

mindspore.numpy.isin(element, test_elements, invert=False)[源代码]

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.

说明

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

参数
  • element (Union[int, float, bool, list, tuple, Tensor]) – Input array.

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

  • invert (boolean, optional) – If True, the values in the returned array are inverted, as if calculating element not in test_elements. Default is False.

返回

Tensor, has the same shape as element. The values element[isin] are in test_elements.

Supported Platforms:

Ascend GPU CPU

样例

>>> element = 2*np.arange(4).reshape((2, 2))
>>> test_elements = [1, 2, 4, 8]
>>> mask = np.isin(element, test_elements)
>>> print(mask)
[[False  True]
[ True False]]
>>> mask = np.isin(element, test_elements, invert=True)
>>> print(mask)
[[ True False]
[False  True]]