unique¶
-
paddle.fluid.layers.
unique
(x, dtype='int32')[source] unique
Return a unique tensor for x and an index tensor pointing to this unique tensor.
- Parameters
x (Variable) – A 1-D input tensor.
dtype (np.dtype|core.VarDesc.VarType|str) – The type of index tensor: int32, int64.
- 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.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]