torch.argmax 可以返回一个值在张量中展平后的索引位置在这种条件下要得到最大的值,要先把张量展平才能得到相应的值
t1 = torch.Tensor([[1,2,3,4],[2,2,3,4]]) t1
tensor([[1., 2., 3., 4.],
[2., 2., 3., 4.]])
index = torch.argmax(t1) index
tensor(3)
t1.view(-1)[index]
tensor(4.)参考文献
pytorch查找矩阵中最大元素的值和索引



