Pytorch 合并与分割

Pytorch 合并与分割

cat Statistics about scores
import torch
a = torch.rand(4, 32, 8)
print("a.shape:\t", a.shape)

b = torch.rand(5, 32, 8)
print("b.shape:\t", b.shape)

c = torch.cat([a, b], dim = 0).shape
print("c:\t", c)
a.shape:	 torch.Size([4, 32, 8])
b.shape:	 torch.Size([5, 32, 8])
c:	 torch.Size([9, 32, 8])
import torch
a1 = torch.rand(4, 3, 32, 32)
a2 = torch.rand(5, 3, 32, 32)

a3 = torch.rand(4, 1, 32, 32)
c = torch.cat([a1, a3], dim=1).shape
print("c:\t", c)

a4 = torch.rand(4, 3, 16, 32)
d = torch.cat([a1, a4], dim=2).shape
print("d:\t", d)
c:	 torch.Size([4, 4, 32, 32])
d:	 torch.Size([4, 3, 48, 32])
stack: ccreate new
import torch
a1 = torch.rand(4, 3, 32, 32)
a2 = torch.rand(4, 3, 32, 32)

b = torch.stack([a1, a2], dim=2).shape
print("b:\t", b)

c = torch.rand(32, 8)
d = torch.rand(32, 8)

e = torch.stack([c, d], dim=0).shape
print("e:\t", e)
b:	 torch.Size([4, 3, 2, 32, 32])
e:	 torch.Size([2, 32, 8])
Split:
import torch
a = torch.rand(32, 8)
b = torch.rand(32, 8)
print("a.shape:\t", a.shape)

c = torch.stack([a, b], dim=0)
print("c.shape:\t", c.shape)

aa, bb = c.split([1,1], dim=0)
print("aa:\t", aa.shape)
print("bb:\t", bb.shape)

cc, dd = c.split(1, dim=0)
print("cc:\t", cc.shape)
print("dd:\t", dd.shape)
a.shape:	 torch.Size([32, 8])
c.shape:	 torch.Size([2, 32, 8])
aa:	 torch.Size([1, 32, 8])
bb:	 torch.Size([1, 32, 8])
cc:	 torch.Size([1, 32, 8])
dd:	 torch.Size([1, 32, 8])
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值