tensor.unique
Identifies the unique elements or subtensors of a tensor, with an optional axis parameter for subtensor slicing. This function returns a tuple containing the tensor of unique elements or subtensors, and optionally, tensors for indices, inverse indices, and counts of unique elements.
axis
(Option<i32>
) - Specifies the dimension along which to find unique subtensors. A None value means the unique elements of the tensor will be returned in a flattened form. A negative value indicates dimension counting from the end.sorted
(Option<bool>
) - Determines if the unique elements should be returned in ascending order. Defaults to true.
Returns
A tuple containing:
A Tensor with unique values or subtensors from self.
A Tensor with the first occurrence indices of unique elements in self. If axis is given, it returns indices along that axis; otherwise, it refers to the flattened tensor.
A Tensor mapping each element of self to its index in the unique tensor. If axis is specified, it maps to the subtensor index; otherwise, it maps to the unique flattened tensor.
A Tensor for the counts of each unique element or subtensor in self.
Example
or
Last updated