torch.cat---dim=num

— 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]]])
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值