mindspore.numpy.intersect1d
- mindspore.numpy.intersect1d(ar1, ar2, assume_unique=False, return_indices=False)[源代码]
Find the intersection of two Tensors. Return the sorted, unique values that are in both of the input Tensors.
- 参数
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
.return_indices (bool) – If True, the indices which correspond to the intersection of two Tensors are returned. The first instance of a value is used if there are multiple. Default:
False
.
- 返回
Tensor or tuple of Tensors. If return_indices is
False
, return the intersection tensor, otherwise return tuple of tensors.- 异常
- Supported Platforms:
Ascend
GPU
CPU
样例
>>> import mindspore.numpy as np >>> np.intersect1d([1, 3, 4, 3], [3, 1, 2, 1]) Tensor(shape=[2], dtype=Int32, value=[1, 3])