mindspore.ops.unique

View Source On Gitee
mindspore.ops.unique(input)[source]

Remove duplicate elements from the input tensor.

Warning

This is an experimental API that is subject to change or deletion.

Parameters

input (Tensor) – The input tensor.

Returns

Tuple(output, indices) of 2 tensors.

  • output (Tensor) - The deduplicated output tensor.

  • indices (Tensor) - The indices of the elements of the input tensor in the output .

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> x = mindspore.tensor([1, 2, 5, 2], mindspore.int32)
>>> output, indices = mindspore.ops.unique(x)
>>> print(output)
[1, 2, 5]
>>> print(indices)
[0, 1, 2, 1]