持之以恒

导航

pytorh API

https://pytorch.org/docs/master/jit.html
https://pytorch.org/tutorials/

torch.cat
python
In [8]: import torch
...: A=torch.ones(2,3) #2x3的张量(矩阵)
...: B=2torch.ones(4,3) #4x3的张量(矩阵)
...: C=torch.cat((A,B),0) #按维数0(行)拼接
...: print("A:",A)
...: print("B:",B)
...: print("C=cat(A,B,0):",C)
...: print(C.size())
...:
...: D=2
torch.ones(2,4) #2x4的张量(矩阵)
...: C=torch.cat((A,D),1)#按维数1(列)拼接
...:
...: print("D:",D)
...: print("C=cat(A,D,1):",C)
...: C.size()
...:
python

A: tensor([[1., 1., 1.],
[1., 1., 1.]])
B: tensor([[2., 2., 2.],
[2., 2., 2.],
[2., 2., 2.],
[2., 2., 2.]])
C=cat(A,B,0): tensor([[1., 1., 1.],
[1., 1., 1.],
[2., 2., 2.],
[2., 2., 2.],
[2., 2., 2.],
[2., 2., 2.]])
torch.Size([6, 3])
D: tensor([[2., 2., 2., 2.],
[2., 2., 2., 2.]])
C=cat(A,D,1): tensor([[1., 1., 1., 2., 2., 2., 2.],
[1., 1., 1., 2., 2., 2., 2.]])
Out[8]: torch.Size([2, 7])

posted on 2021-09-27 22:21  beilei  阅读(25)  评论(0编辑  收藏  举报