torch.topk
-
torch.topk(input, k, dim=None, largest=True, sorted=True, *, out=None) -> (Tensor, LongTensor)
-
Returns the
k
largest elements of the giveninput
tensor along a given dimension.If
dim
is not given, the last dimension of theinput
is chosen.If
largest
isFalse
then thek
smallest elements are returned.A namedtuple of
(values, indices)
is returned, where theindices
are the indices of the elements in the originalinput
tensor.The boolean option
sorted
ifTrue
, will make sure that the returnedk
elements are themselves sorted- Parameters
- Keyword Arguments
-
out (tuple, optional) – the output tuple of (Tensor, LongTensor) that can be optionally given to be used as output buffers
Example:
>>> x = torch.arange(1., 6.) >>> x tensor([ 1., 2., 3., 4., 5.]) >>> torch.topk(x, 3) torch.return_types.topk(values=tensor([5., 4., 3.]), indices=tensor([4, 3, 2]))
© 2019 Torch Contributors
Licensed under the 3-clause BSD License.
https://pytorch.org/docs/1.8.0/generated/torch.topk.html