The size of tensor a (4) must match the size of tensor b (2) at non-singleton dimension 0
a1与a2维度不一样就会报这个错:
import torch import numpy as np # 80 10 5 3:4 # 80 3 11 11 import copy a = torch.linspace(-4, -1, steps=4) a = torch.linspace(0, 1, steps=2).repeat(16,1).view(16,2) b = torch.linspace(1, 256, steps=256).view(8,8, 4) print(np.array(a)) print(b<5) #取单个值, a=[[0,0,0,1],[0,0,0,2]]#维度变了 a1=np.asarray([0,0,0,1])#维度变了 a2=np.asarray([0,2])#维度变了 b[a1,a2]=0 print(b)