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