PyTorch torch.kthvalue function
PyTorch torch reference manual
torch.kthvalue is a function in PyTorch used to return the k-th smallest value. It returns the k-th smallest value of the input tensor along the specified dimension and its index.
Function definition
torch.kthvalue(input, k, dim=None, keepdim=False)
Usage examples
Example
import
torch
Creating tensors
x
=
torch.
tensor
(
[
3
,
1
,
2
,
4
]
)
Return the 2nd smallest value and its index
values
,
indices
=
torch.
kthvalue
(
x
,
2
)
(
values
)
(
indices
)
The output is:
tensor(2)
tensor(2)