fn

sort

tuple of (Tensor, Tensor)
sort(input: Tensor, dim: DimLike = ...)
source

Sort input along dim in ascending order and return values + indices.

The sort is stable: equal keys retain their relative order. For descending order, negate the input or post-process the returned indices.

Parameters

inputTensor
Source tensor.
dimDimLike= ...
Axis to sort along.

Returns

tuple of (Tensor, Tensor)

(sorted_values, indices) — values sorted along dim, and the indices into input that produce them.

Notes

input[indices] == sorted_values along dim. See argsort for the index-only variant.

Examples

>>> import lucid
>>> x = lucid.tensor([3, 1, 2])
>>> lucid.sort(x, dim=0)
(Tensor([1, 2, 3]), Tensor([1, 2, 0]))