参数:
代码
import torch
x = torch.randn(2, 3)
print(torch.cat((x, x, x))) #默认按行连接张量
print(torch.cat((x, x, x), 0)) #按行连接张量
print(torch.cat((x, x, x), 1)) #按列连接张量
运行结果:
tensor([[-0.4339, -0.2350, -2.1694],
[ 1.2595, -0.8431, 0.4704],
[-0.4339, -0.2350, -2.1694],
[ 1.2595, -0.8431, 0.4704],
[-0.4339, -0.2350, -2.1694],
[ 1.2595, -0.8431, 0.4704]])
tensor([[-0.4339, -0.2350, -2.1694],
[ 1.2595, -0.8431, 0.4704],
[-0.4339, -0.2350, -2.1694],
[ 1.2595, -0.8431, 0.4704],
[-0.4339, -0.2350, -2.1694],
[ 1.2595, -0.8431, 0.4704]])
tensor([[-0.4339, -0.2350, -2.1694, -0.4339, -0.2350, -2.1694, -0.4339, -0.2350,
-2.1694],
[ 1.2595, -0.8431, 0.4704, 1.2595, -0.8431, 0.4704, 1.2595, -0.8431,
0.4704]])