unique

paddle.fluid.layers.nn. unique ( x, dtype='int32' ) [source]

Return a unique tensor for x and an index tensor pointing to this unique tensor.

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

  • dtype (np.dtype|str, optional) – The type of index tensor: int32, int64. Default: int32.

Returns

(out, index). out is the unique tensor for x, with identical dtype to x, and

index is an index tensor pointing to out, by which user can recover the original x tensor.

Return type

tuple

Examples

import numpy as np
import paddle.fluid as fluid
x = fluid.layers.assign(np.array([2, 3, 3, 1, 5, 3], dtype='int32'))
out, index = fluid.layers.unique(x) # out is [2, 3, 1, 5]; index is [0, 1, 1, 2, 3, 1]