# unique¶

paddle. unique ( x, return_index=False, return_inverse=False, return_counts=False, axis=None, dtype='int64', name=None ) [source]

Returns the unique elements of x in ascending order.

Parameters
• x (Tensor) – The input tensor, it’s data type should be float32, float64, int32, int64.

• return_index (bool, optional) – If True, also return the indices of the input tensor that result in the unique Tensor.

• return_inverse (bool, optional) – If True, also return the indices for where elements in the original input ended up in the returned unique tensor.

• return_counts (bool, optional) – If True, also return the counts for each unique element.

• axis (int, optional) – The axis to apply unique. If None, the input will be flattened. Default: None.

• dtype (np.dtype|str, optional) – The date type of indices or inverse tensor: int32 or int64. Default: int64.

• name (str, optional) – Name for the operation. For more information, please refer to Name. Default: None.

Returns

tuple (out, indices, inverse, counts). out is the unique tensor for x. indices is

provided only if return_index is True. inverse is provided only if return_inverse is True. counts is provided only if return_counts is True.

Examples

```import paddle

x = paddle.to_tensor([2, 3, 3, 1, 5, 3])
np_unique = unique.numpy() # [1 2 3 5]
_, indices, inverse, counts = paddle.unique(x, return_index=True, return_inverse=True, return_counts=True)
print(indices)
#        [3, 0, 1, 4])
print(inverse)
#        [1, 2, 2, 0, 3, 2])
print(counts)
#        [1, 1, 3, 1])

x = paddle.to_tensor([[2, 1, 3], [3, 0, 1], [2, 1, 3]])