PyTorch torch.argsort function
PyTorch torch reference manual
torch.argsort is a function in PyTorch used to return the sorted indices. It returns the indices of the original positions of the elements after sorting the tensor.
Function definition
torch.argsort(input, dim=-1, descending=False, stable=True)
Usage examples
Example
import
torch
Creating tensors
x
=
torch.
tensor
(
[
3
,
1
,
2
]
)
Return the sorted indices
indices
=
torch.
argsort
(
x
)
(
indices
)
The output is:
tensor([1, 2, 0])