Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.argsort function

PyTorch torch.argsort function


PyTorch torch reference manual 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

)

print

(

indices

)

The output is:

tensor([1, 2, 0])


PyTorch torch reference manual PyTorch torch reference manual