unique¶
dragon.
unique
(
inputs,
return_inverse=False,
return_counts=False,
**kwargs
)[source]¶Return the unique elements of input.
If
return_inverse
, return the extra index where input mapping to:x = dragon.constant([1, 2, 3, 2]) y, index = dragon.unique(x, return_inverse=True) print(y) # [1, 2, 3] print(index) # [0, 1, 2, 1]
If
return_counts
, return the extra counts of output:x = dragon.constant([1, 2, 3, 2]) y, counts = dragon.unique(x, return_counts=True) print(y) # [1, 2, 3] print(counts) # [1, 2, 1]
- Parameters:
- inputs (dragon.Tensor) – The input tensor.
- return_inverse (bool, optional, default=False) – Return the inverse index or not.
- return_counts (bool, optional, default=False) – Return the counts or not.
- Returns:
- dragon.Tensor – The output tensor.
- dragon.Tensor, optional – The inverse index tensor.
- dragon.Tensor, optional – The counts tensor.