mindspore.numpy.in1d
- mindspore.numpy.in1d(ar1, ar2, invert=False)[源代码]
- 测试一维数组的每个元素是否也存在于第二个数组中。 返回与 - ar1长度相同的boolean数组,当- ar1的某个元素存在于- ar2中时,该位置为True,否则为False。- 说明 - 不支持Numpy的 - assume_unique参数,因为该实现不依赖于输入数组的唯一性。- 参数:
- ar1 (Union[int, float, bool, list, tuple, Tensor]) - shape为 - (M,)的输入数组。
- ar2 (Union[int, float, bool, list, tuple, Tensor]) - 用于测试 - ar1中每个值的数组。
- invert (boolean, 可选) - 如果为True,返回数组中的值将被反转(即当 - ar1的元素在- ar2中时为False,否则为True)。默认值:- False。
 
- 返回:
- Tensor,shape为 - (M,)。值为- ar1中元素是否存在于- ar2中的真值。
- 支持平台:
- Ascend- GPU- CPU
 - 样例: - >>> import mindspore.numpy as np >>> 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]