mindspore.numpy.setdiff1d

mindspore.numpy.setdiff1d(ar1, ar2, assume_unique=False)[源代码]

Find the set difference of two Tensors. Return the unique values in ar1 that are not in ar2.

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

  • ar2 (Union[int, float, bool, list, tuple, Tensor]) – Input tensor.

  • assume_unique (bool) – If True, the input Tensors are 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: False.

返回

1D Tensor of values in ar1 that are not in ar2. The result is sorted when assume_unique = False , but otherwise only sorted if the input is sorted.

异常
  • TypeError – If input ar1 or ar2 is not array_like.

  • TypeError – If assume_unique is not bool.

Supported Platforms:

Ascend GPU CPU

样例

>>> import mindspore.numpy as np
>>> a = np.array([1, 2, 3, 2, 4, 1])
>>> b = np.array([3, 4, 5, 6])
>>> np.setdiff1d(a, b)
Tensor(shape=[2], dtype=Int32, value=[1, 2])