在pytorch中, 想删除tensor中的指定行列,原本以为有个函数或者直接把某一行赋值为[]
就可以,结果发现没这么简单,因此用了一个曲线救国方法,希望如果有更直接的方法,请大家指出。
shot = args.support_shot # 5
way = args.way # 5
data = data_ori.reshape(shot, way, 3, 84, 84)
anc = data[:, p]
pos = anc.repeat(4, 1, 1, 1)
neg = data[:, torch.arange(way) != p].reshape(shot * (way - 1), 3, 84, 84)
a = torch.rand(4, 2)
print(a)
idx = 1
a = a[torch.arange(a.size(0))!=1]
print(a)
"""
tensor([[2.7775e-01, 3.7430e-01],
[9.0373e-01, 8.1220e-02],
[9.8638e-01, 8.6293e-01],
[9.8139e-04, 9.8460e-02]])
tensor([[2.7775e-01, 3.7430e-01],
[9.8638e-01, 8.6293e-01],
[9.8139e-04, 9.8460e-02]])
"""