0
点赞
收藏
分享

微信扫一扫

Pytorch学习之:索引出一个 tensor 中的最大值及其所在的位置 torch.argmax

代码

  • 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查找矩阵中最大元素的值和索引

举报

相关推荐

0 条评论