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

PyTorch torch.sort function

PyTorch torch.sort function


PyTorch torch reference manual PyTorch torch reference manual

torch.sort is a function in PyTorch used to sort along a specified dimension.

Function definition

torch.sort(input, dim, descending, stable, out)


Usage examples

Example

import

torch

x

=

torch.

tensor

(

[

[

3

,

1

,

2

]

,

[

6

,

4

,

5

]

]

)

Sorting

values

,

indices

=

torch.

sort

(

x

)

print

(

"Sorted values:"

)

print

(

values

)

print

(

"Sorted indices:"

)

print

(

indices

)

Sort in descending order

values_desc

,

_

=

torch.

sort

(

x

,

descending

=

True

)

print

(

"Descending:"

)

print

(

values_desc

)


PyTorch torch reference manual PyTorch torch reference manual