torch.cat
A=torch.ones(2,4)
print(A)
B=2*torch.ones(2,4)
print(B)
C=torch.cat((A,B),0)
print(C)
D=torch.cat((A,B),1)
print(D)
#A的输出
tensor([[1., 1., 1., 1.],
[1., 1., 1., 1.]])
#B的输出
tensor([[2., 2., 2., 2.],
[2., 2., 2., 2.]])
#C的输出
tensor([[1., 1., 1., 1.],
[1., 1., 1., 1.],
[2., 2., 2., 2.],
[2., 2., 2., 2.]])
#D的输出
tensor([[1., 1., 1., 1., 2., 2., 2., 2.],
[1., 1., 1., 1., 2., 2., 2., 2.]])
torch.sum
E=torch.sum(A,0)
print(E)
F=torch.sum(A,1)
print(F)
#E的输出
tensor([2., 2., 2., 2.])
#F的输出
tensor([4., 4.])