Skip to content
fn

argsort

→Tensor
argsort(input: Tensor, dim: _int = ..., descending: _bool = ..., stable: _bool = ...)

Implementing kernel

C++ engine symbols that back this Python API.

Return the indices that would sort input along dim.

Gathering input with the returned tensor along dim gives sort's result.

Parameters

inputTensor
Source tensor.
dimint= -1
Axis along which to sort.
descendingbool= False
Order largest first.

Returns

Tensor

Integer index tensor of the same shape as input.

Notes

The sort is stable in both directions: equal keys keep their input order, descending included. NaN sorts as the largest value.

Examples

>>> import lucid
>>> x = lucid.tensor([3, 1, 4, 1, 5])
>>> lucid.argsort(x, dim=0)
Tensor([1, 3, 0, 2, 4])
>>> lucid.argsort(x, dim=0, descending=True)
Tensor([4, 2, 0, 1, 3])