PyTorch torch.sort function
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
)
(
"Sorted values:"
)
(
values
)
(
"Sorted indices:"
)
(
indices
)
Sort in descending order
values_desc
,
_
=
torch.
sort
(
x
,
descending
=
True
)
(
"Descending:"
)
(
values_desc
)