Bug:IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1)

Bug:IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1)

代码:

a=torch.tensor([2,1])
b=torch.chunk(a,2,1)

错误原因:

print(a.shape)
torch.Size([2])

a 的 shape 是[2] ,不是[1,2],是一个一维向量,因此 不存在 dim=1的情况

修改

b=torch.chunk(a,2,0)
b=torch.chunk(a,2,-1)

你可能感兴趣的:(pytorch,bug,python)