mindspore.dataset.transforms.Unique

class mindspore.dataset.transforms.Unique[source]

Perform the unique operation on the input tensor, only support transform one column each time.

Return 3 tensor: unique output tensor, index tensor, count tensor.

  • Output tensor contains all the unique elements of the input tensor in the same order that they occur in the input tensor.

  • Index tensor that contains the index of each element of the input tensor in the unique output tensor.

  • Count tensor that contains the count of each element of the output tensor in the input tensor.

Note

Call batch op before calling this function.

Raises

RuntimeError – If given Tensor has two columns.

Supported Platforms:

CPU

Examples

>>> # Data before
>>> # |  x                 |
>>> # +--------------------+
>>> # | [[0,1,2], [1,2,3]] |
>>> # +--------------------+
>>> data = [[[0,1,2], [1,2,3]]]
>>> dataset = ds.NumpySlicesDataset(data, ["x"])
>>> dataset = dataset.map(operations=transforms.Unique(),
...                       input_columns=["x"],
...                       output_columns=["x", "y", "z"],
...                       column_order=["x", "y", "z"])
>>> # Data after
>>> # |  x      |  y              |z        |
>>> # +---------+-----------------+---------+
>>> # | [0,1,2,3] | [0,1,2,1,2,3] | [1,2,2,1]
>>> # +---------+-----------------+---------+