栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

pytorch中的拆分函数:split()和chunk()

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

pytorch中的拆分函数:split()和chunk()

文章目录
  • Ⅰ.split([tensor a, tensor b, ...], dim = i) 助记:“根据长度不平均拆分”
    • 一、作用
    • 二、常用
    • 三、特殊
    • 四、代码
  • Ⅱ.split(tensor a, dim = i) 助记:“根据长度平均拆分”
    • 一、作用
    • 二、常用
    • 三、特殊
    • 四、代码
  • Ⅲ.chunk(tensor a, dim = i) 助记:“根据生成Tensor数量平均拆分”
    • 一、作用
    • 二、常用
    • 三、特殊
    • 四、代码

Ⅰ.split([tensor a, tensor b, …], dim = i) 助记:“根据长度不平均拆分” 一、作用

1-1. 将Tensor第i个维度上的维度数拆分为a、b、…,从而生成n个新的Tensor。要保证实际可拆。

二、常用

2-1. 见In[4]

三、特殊

3-1. 无

四、代码
In[2]: import torch
In[3]: c = torch.rand(4, 3, 2)
In[4]: a, b =c.split([3, 1], dim = 0)
In[5]: a.shape, b.shape
Out[5]: (torch.Size([3, 3, 2]), torch.Size([1, 3, 2]))
Ⅱ.split(tensor a, dim = i) 助记:“根据长度平均拆分” 一、作用

1-1. 将Tensor第i个维度上的维度数用a平均拆分。要确保Tensor维度上的维度数能整除a,使生成的Tensor个数为整数。

二、常用

2-1. 见In[4]

三、特殊

3-1. 无

四、代码
In[2]: import torch
In[3]: c = torch.rand(4, 3, 2)
In[4]: a, b, d, e = c.split(1, dim = 0)
In[5]: a.shape, b.shape, d.shape, e.shape
Out[5]: 
(torch.Size([1, 3, 2]),
 torch.Size([1, 3, 2]),
 torch.Size([1, 3, 2]),
 torch.Size([1, 3, 2]))
Ⅲ.chunk(tensor a, dim = i) 助记:“根据生成Tensor数量平均拆分” 一、作用

1-1. 将Tensor第i个维度上的维度数 ÷ a平均拆分。要确保Tensor维度上的维度数能整除a,使生成的Tensor上的tensor为整数。

二、常用

2-1. 见In[9]

三、特殊

3-1. 无

四、代码
In[8]: c = torch.rand(6, 3, 2)
In[9]: a, b = c.chunk(2, dim = 0)
In[10]: a.shape, b.shape
Out[10]: (torch.Size([3, 3, 2]), torch.Size([3, 3, 2]))

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/950289.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号