mindspore.numpy.setdiff1d

View Source On Gitee
mindspore.numpy.setdiff1d(ar1, ar2, assume_unique=False)[source]

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

Parameters
  • 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.

Returns

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.

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

  • TypeError – If assume_unique is not bool.

Supported Platforms:

Ascend GPU CPU

Examples

>>> 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])