文件名:【pytorch】torch.gather()函数,任天堂wii
【pytorch】torch.gather()函数
dim=0时 index=[ [x1,x2,x2],[y1,y2,y2],[z1,z2,z3] ]如果dim=0填入方式为:index=[ [(x1,0),(x2,1),(x3,2)][(y1,0),(y2,1),(y3,2)][(z1,0),(z2,1),(z3,2)] ] input = [[1, 2, 3, 4],[5, 6, 7, 8],[9, 10, 11, 12]] # shape(3,4)input = torch.tensor(input)length = torch.LongTensor([[2,2,2,2],[1,1,1,1],[0,0,0,0],[0,1,2,0]])# shape(4,4)out = torch.gather(input, dim=0, index=length)print(out) tensor([[9, 10, 11, 12],[5, 6, 7, 8],[1, 2, 3, 4],[1, 6, 11, 4]]) #### dim=0后,根据new_index对input进行索引new_index=[ [(2,0),(2,1),(2,2),(2,3)],[(1,0),(1,1),(1,2),(1,3)],[(0,0),(0,1),(0,2),(0,3)],[(0,0),(1,1),(2,2),(0,3)] ]可以观察到第四行,行索引变为0,所以当gather函数里的index超过input的唯独时,会从0重新计数。
dim=1时 input = [[1, 2, 3, 4],[5, 6, 7, 8],[9, 10, 11, 12]] # shape(3,4)input = torch.tensor(input)length = torch.LongTensor([[2,2,2,2],[1,1,1,1],[0,1,2,0]]) # shape(3,4)out = torch.gather(input, dim=1, index=length)print(out) tensor([[3, 3, 3, 3],[6, 6, 6, 6],[9, 10, 11, 9]]) new_index = [[(0,2),(0,2),(0,2),(0,2)],[(1,1),(1,1),(1,1),(1,1)],[(2,0),(2,1),(2,2)(2,0)]]
【pytorch】torch.gather()函数,任天堂wii
0evadmin
编程语言
13
同类推荐
-

【PyQt学习篇 · ⑪】:QPushButton和QCommandLinkButton的使用,声卡报价
查看 -

【Python CheckiO 题解】Days Between,摩托罗拉 ex223
查看 -

【Python_PySide2学习笔记(十八)】勾选按钮QCheckBox类的基本用法,漫步者m12
查看 -

【Python】Python给工作减负-读Excel文件生成xml文件,黛芙薇尔让我祛斑成功
查看 -

【Python】【数据结构和算法】保留最后N个元素,旭日125a(python的保留)
查看 -

【Python】一文带你掌握数据容器之集合,字典,康佳梵高手机
查看 -

【Python】图像和办公文档的处理,联想锋行
查看 -

【Python】字符串和变量拼接的写法,中国移动m701(python 字符串和变量拼接)
查看 -

【Python】异常、模块与包,vista驱动(python模块错误)
查看
控制面板
网站分类
搜索
最新留言
文章归档
网站收藏
友情链接