看网上看多没讲的不是很明白,我来试试空间上的理解
# 假设是时间步T1的输出
T1 = torch.tensor([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
# 假设是时间步T2的输出
T2 = torch.tensor([[10, 20, 30],
[40, 50, 60],
[70, 80, 90]])
输出:
print(torch.stack((T1,T2),dim=0).shape)
print(torch.stack((T1,T2),dim=1).shape)
print(torch.stack((T1,T2),dim=2).shape)
print(torch.stack((T1,T2),dim=3).shape)
# outputs:
torch.Size([2, 3, 3])
torch.Size([3, 2, 3])
torch.Size([3, 3, 2])
'选择的dim>len(outputs),所以报错'
IndexError: Dimension out of range (expected to be in range of [-3, 2], but got 3)
将dim=0,1,2理解为x,y,z轴.
- 那么dim=0的拼接就是在x轴上:这么看,就是x=2,y=3,z=3
- dim = 1,这么看,x=3,y=2,z=3
- dim = 2,这么看,x=3,y=3,z=2
我偷懒了,图就是意思意思