pytorch中的torch.chunk()和torch.split()切片函数

 案例:

import torch

a = torch.rand(size=[3,4])
print(a)
out = torch.chunk(a, 2, dim=0)
print(out)


a = torch.rand(size=[3,4])
print(a)
out = torch.split(a, 2, dim=0)
print(out)

a = torch.rand(size=[6,4])
print(a)
out = torch.split(a, [2,4], dim=0)
print(out)

"""
out:
tensor([[0.4318, 0.9049, 0.8166, 0.3588],
        [0.6499, 0.5793, 0.9395, 0.6760],
        [0.2342, 0.9079, 0.2751, 0.6862]])
(tensor([[0.4318, 0.9049, 0.8166, 0.3588],
        [0.6499, 0.5793, 0.9395, 0.6760]]), tensor([[0.2342, 0.9079, 0.2751, 0.6862]]))
tensor([[0.2170, 0.0928, 0.9245, 0.3909],
        [0.6361, 0.4667, 0.5978, 0.4724],
        [0.1860, 0.4510, 0.1610, 0.9921]])
(tensor([[0.2170, 0.0928, 0.9245, 0.3909],
        [0.6361, 0.4667, 0.5978, 0.4724]]), tensor([[0.1860, 0.4510, 0.1610, 0.9921]]))
tensor([[0.6844, 0.9560, 0.7572, 0.0400],
        [0.4103, 0.3539, 0.1543, 0.5854],
        [0.7305, 0.9435, 0.8111, 0.6618],
        [0.5152, 0.9562, 0.2030, 0.3958],
        [0.3747, 0.8432, 0.9954, 0.4090],
        [0.6239, 0.3010, 0.6631, 0.2251]])
(tensor([[0.6844, 0.9560, 0.7572, 0.0400],
        [0.4103, 0.3539, 0.1543, 0.5854]]), tensor([[0.7305, 0.9435, 0.8111, 0.6618],
        [0.5152, 0.9562, 0.2030, 0.3958],
        [0.3747, 0.8432, 0.9954, 0.4090],
        [0.6239, 0.3010, 0.6631, 0.2251]]))

Process finished with exit code 0


"""

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

浅蓝的风

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值