Skip to content
fn

unique

→Tensor or tuple of Tensor
unique(input: Tensor, sorted: _bool = ..., return_inverse: _bool = ..., return_counts: _bool = ..., dim: _int | None = ...)

Implementing kernel

C++ engine symbols that back this Python API.

Return the sorted unique elements of input.

Duplicate values are removed and the output is sorted in ascending order. By default the input is flattened; with dim the unique values are whole slices along that dim.

Parameters

inputTensor
Source tensor.
sortedbool= True
Accepted for compatibility; the values always come back sorted.
return_inversebool= False
Also return, for every element (or slice along dim), the position of its value in the output — in input's shape, or one entry per slice.
return_countsbool= False
Also return how many times each unique value occurs.
dimint= ...
Dim whose slices are compared; None flattens input.

Returns

Tensor or tuple of Tensor

The unique values, followed by the int64 inverse and counts when asked for.

Notes

Because the output size is data-dependent this op forces a host round-trip on accelerator backends.

Examples

>>> import lucid
>>> x = lucid.tensor([3, 1, 2, 3, 1, 4])
>>> lucid.unique(x)
Tensor([1, 2, 3, 4])