当(x,y)为两个二维张量情况下
1.torch.cat((x,y),dim = 0)
import torch
x = torch.rand(3,4)
print(x)
y = torch.rand(3,4)
print(y)
a = torch.cat((x,y),dim = 0)
print(a)
结果为:
解释:
dim = 0 意味着在第0维度方向(第0维也就是行为3的方向)进行叠加,如图所示:
2.torch.cat((x,y),dim = 1)
import torch
x = torch.rand(3,4)
print(x)
y = torch.rand(3,4)
print(y)
a = torch.cat((x,y),dim = 1)
print(a)
结果为:
解释:
dim = 1 意味着在第1维度方向(第1维也就是列为4的方向)进行叠加,如图所示:
总结
对于更高维的数据,也就是在dim = x 时,即x所对应维度方向进行叠加。