import torch
A = torch.ones(2,3)
B = torch.ones(2,3)*2
print('A:',A)
print('A:',A.shape)
print('----------------------')
print('B:',B)
print('B:',B.shape)
print('-----------------------')
C = torch.cat((A, B)) #默认dim=0
print('C:',C)
print('C:',C.shape)
print('_______________________')
D = torch.cat((A, B), dim=1)
print('D:',D)
print('D:',D.shape)
清晰可见:dim=0按行拼接, dim=1按列拼接。