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

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

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

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5711891.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-18

发表评论

登录后才能评论

评论列表(0条)

保存