— dim=0
from functools import reduce
import torch
a=torch.randn(1,3,3)
tensor([[[-1.3366, -0.7503, 0.8280],
[-0.6265, 0.5649, -1.0375],
[-1.7299, -0.0394, 0.4885]]])
b=torch.randn(1,3,3)
tensor([[[ 1.6557, 0.1908, -0.3583],
[ 0.2740, 0.5985, 0.2180],
[-0.4295, 1.6998, 0.3194]]])
d=torch.randn(1,3,3)
tensor([[[-0.5914, -3.3615, -0.1838],
[ 0.8650, 0.5169, 0.1650],
[-0.9087, -0.7443, 0.6909]]])
c=[a,b,d]
[tensor([[[-1.3366, -0.7503, 0.8280],
[-0.6265, 0.5649, -1.0375],
[-1.7299, -0.0394, 0.4885]]]), tensor([[[ 1.6557, 0.1908, -0.3583],
[ 0.2740, 0.5985, 0.2180],
[-0.4295, 1.6998, 0.3194]]]), tensor([[[-0.5914, -3.3615, -0.1838],
[ 0.8650, 0.5169, 0.1650],
[-0.9087, -0.7443, 0.6909]]])]
e = reduce(lambda x, y: torch.cat((x, y), dim=0), c)
tensor([[[-1.3366, -0.7503, 0.8280],
[-0.6265, 0.5649, -1.0375],
[-1.7299, -0.0394, 0.4885]],
[[ 1.6557, 0.1908, -0.3583],
[ 0.2740, 0.5985, 0.2180],
[-0.4295, 1.6998, 0.3194]],
[[-0.5914, -3.3615, -0.1838],
[ 0.8650, 0.5169, 0.1650],
[-0.9087, -0.7443, 0.6909]]])
— dim=1
e = reduce(lambda x, y: torch.cat((x, y), dim=1), c)
tensor([[[-1.3366, -0.7503, 0.8280],
[-0.6265, 0.5649, -1.0375],
[-1.7299, -0.0394, 0.4885],
[ 1.6557, 0.1908, -0.3583],
[ 0.2740, 0.5985, 0.2180],
[-0.4295, 1.6998, 0.3194],
[-0.5914, -3.3615, -0.1838],
[ 0.8650, 0.5169, 0.1650],
[-0.9087, -0.7443, 0.6909]]])
— dim=2
e = reduce(lambda x, y: torch.cat((x, y), dim=2), c)
tensor([[[-1.3366, -0.7503, 0.8280, 1.6557, 0.1908, -0.3583, -0.5914,
-3.3615, -0.1838],
[-0.6265, 0.5649, -1.0375, 0.2740, 0.5985, 0.2180, 0.8650,
0.5169, 0.1650],
[-1.7299, -0.0394, 0.4885, -0.4295, 1.6998, 0.3194, -0.9087,
-0.7443, 0.6909]]])