二维tensor的一次索引出给对定对应索引位置的值

outputs = torch.tensor([[ 0.6579, -2.1024, -0.4000],

          [-0.3348, -0.4195, -1.5200],

          [-0.3317,  0.6184,  1.7048],

          [-0.1368, -1.1512, -0.6306],

          [-0.3990, -1.2909, -0.8157]])

labels =  torch.tensor([0, 0, 1, 2, 1])

print(outputs[range(5), labels])
# tensor([ 0.6579, -0.3348,  0.6184, -0.6306, -1.2909])

"""
tensor1[   (0:5),    [0, 0, 1, 2, 1]  ]

"""

posted @ 2020-09-15 18:36  Parallax  阅读(623)  评论(0编辑  收藏  举报