Sort
sort(input, dim=-1, descending=FALSE) -> (Tensor, LongTensor)
Sorts the elements of the input
tensor along a given dimension
in ascending order by value.
If dim
is not given, the last dimension of the input
is chosen.
If descending
is TRUE
then the elements are sorted in descending
order by value.
A namedtuple of (values, indices) is returned, where the values
are the
sorted values and indices
are the indices of the elements in the original
input
tensor.
Examples
if (torch_is_installed()) {
x = torch_randn(c(3, 4))
out = torch_sort(x)
out
out = torch_sort(x, 1)
out
}
#> [[1]]
#> torch_tensor
#> -0.9502 0.2731 -2.9674 -1.5218
#> 0.7463 0.4347 -0.7894 -0.6639
#> 1.4535 0.7934 1.3197 1.2911
#> [ CPUFloatType{3,4} ]
#>
#> [[2]]
#> torch_tensor
#> 1 3 3 2
#> 2 1 2 3
#> 3 2 1 1
#> [ CPULongType{3,4} ]
#>