import torch
m=torch.Tensor([[0.1,0.2,0.3],[0.5,0.6,0.4]])
iou=torch.Tensor([0.5,0.6,0.7])
a=iou > 0.5
print(a)
index=torch.Tensor([1,0,1]).type(torch.ByteTensor)
index0=torch.Tensor([1,1]).type(torch.ByteTensor)
print(index)
x=m[index0,index]
print(x)
m[index0,index]=2
print(m)
结果是:有疑问,index0的值是1或者0,出来的结果都挺奇怪:
tensor([0.1000, 0.4000])
tensor([[2.0000, 0.2000, 0.3000],
[0.5000, 0.6000, 2.0000]])
解释:
byteTensor按位取数据,index0是1,1,则取两组数据
index中,至少有一个1,如果有一个1,两组第二维相同,,如果有两个1,从左到右依次各取一个。
这个会有几个数:
m[torch.Tensor([0,1]).type(torch.ByteTensor),torch.Tenso