pytorch's topk () function

pytorch.topk () is used to return the first k elements in Tensor and their corresponding index values. example:

import torch

item=torch.IntTensor([1,2,4,7,3,2])
value,indices=torch.topk(item,3)
print("value:",value)
print("indices:",indices)

The output is:

 Among them: the value is stored in the corresponding top3 elements, and stored according to the value from large to small

index stores the index value of the top3 element in value in the original Tensor

Published 943 original articles · Like 136 · Visit 330,000+

Guess you like

Origin blog.csdn.net/weixin_36670529/article/details/105227297