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

PyTorch torch.kthvalue function

PyTorch torch.kthvalue function


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

)

print

(

values

)

print

(

indices

)

The output is:

tensor(2)

tensor(2)


PyTorch torch reference manual PyTorch torch reference manual