当前位置:网站首页>【Pytorch】torch.argmax()用法
【Pytorch】torch.argmax()用法
2022-07-31 13:49:00 【风雨无阻啊】
argmax函数:torch.argmax(input, dim=None, keepdim=False)
(1)torch.argmax(input, dim=None, keepdim=False)返回指定维度最大值的序号;
(2)dim给定的定义是:the demention to reduce.也就是把dim这个维度的,变成这个维度的最大值的index。
例如:
import numpy as np
import torch
b = torch.tensor([
[
[8, 10, 14, 21],
[9, 6, 23, 13],
[15, 32,16,11]
],
[
[31,20, 27, 17],
[28, 34, 22,33],
[36, 30, 1, 3]
],
[
[12, 29, 26, 25],
[19, 7, 5, 4],
[2, 35, 24, 18]
]
])
print('b.shape=',b.shape) #b.shape=([3,3,4])
dim_0 = torch.argmax(b,dim = 0)
print('dim_0.shape=',dim_0.shape)
print('dim_0=',dim_0)
dim_1 = torch.argmax(b,dim = 1)
print('dim_1.shape=',dim_1.shape)
print('dim_1=',dim_1)
dim_2 = torch.argmax(b,dim = 2)
print('dim_2.shape=',dim_2.shape)
print('dim_2=',dim_2)
dim_f1 = torch.argmax(b,dim = -1)
print('dim_-1.shape=',dim_f1.shape)
print('dim_-1=',dim_f1)
dim_f2 = torch.argmax(b,dim = -2)
print('dim_-2.shape=',dim_f2.shape)
print('dim_-2=',dim_f2)
代码运行结果:
b.shape= torch.Size([3, 3, 4])
dim_0.shape= torch.Size([3, 4])
dim_0= tensor([[1, 2, 1, 2],
[1, 1, 0, 1],
[1, 2, 2, 2]])
dim_1.shape= torch.Size([3, 4])
dim_1= tensor([[2, 2, 1, 0],
[2, 1, 0, 1],
[1, 2, 0, 0]])
dim_2.shape= torch.Size([3, 3])
dim_2= tensor([[3, 2, 1],
[0, 1, 0],
[1, 0, 1]])
dim_-1.shape= torch.Size([3, 3])
dim_-1= tensor([[3, 2, 1],
[0, 1, 0],
[1, 0, 1]])
dim_-2.shape= torch.Size([3, 4])
dim_-2= tensor([[2, 2, 1, 0],
[2, 1, 0, 1],
[1, 2, 0, 0]])
进程已结束,退出代码为 0
总结:
dim=0,将张量最高维度消除,也就是说将b张量为([3 ,3,4])变为([3,4]);
同理,dim=1,将第二高的维度消除,也就是说将b张量为([3,3 ,4])变为([3,4]);dim=2,将第三高的维度消除,也就是说将b张量为([3,3,4 ])变为([3,3]);以此类推。dim=-1表示张量维度的最低维度 -2表示张量的倒数第二维度,-3表示倒数第三维度。
下一篇:
【Pytorch】F.softmax()方法说明
边栏推荐
- LeetCode·304竞赛·6132·使数组中所有元素都等于零·模拟·哈希
- Resolved (pymysqL connect to the database error) pymysqL. Err. ProgrammingError: (1146, "Table" test. Students' doesn 't exist ")
- LeetCode只出现一次的数字
- 战略进攻能力的重要性,要远远高于战略防守能力
- 技能大赛训练题: 子网掩码划分案例
- Samba 远程命令执行漏洞(CVE-2017-7494)
- leetcode:2032. 至少在两个数组中出现的值
- EXCEL如何快速拆分合并单元格数据
- ECCV2022: Recursion on Transformer without adding parameters and less computation!
- 文本相似度计算(中英文)详解实战
猜你喜欢

纸质说明书秒变3D动画,斯坦福大学吴佳俊最新研究,入选ECCV 2022

The operator,
![[Niu Ke brush questions - SQL big factory interview questions] NO3. E-commerce scene (some east mall)](/img/a6/8d53f5087a33c2bea8c99a5bb922da.png)
[Niu Ke brush questions - SQL big factory interview questions] NO3. E-commerce scene (some east mall)

232层3D闪存芯片来了:单片容量2TB,传输速度提高50%

拥塞控制,CDN,端到端

The Selenium IDE of the Selenium test automation

SetoolKit使用指南

ADS communicate with c #

八大排序汇总及其稳定性

【蓝桥杯选拔赛真题46】Scratch磁铁游戏 少儿编程scratch蓝桥杯选拔赛真题讲解
随机推荐
深度剖析 Apache EventMesh 云原生分布式事件驱动架构
leetcode:2032. Values that appear in at least two arrays
MySQL玩到这种程度,难怪大厂抢着要!
STM32的CAN过滤器
leetcode: 485. Maximum number of consecutive 1s
Buffer 与 拥塞控制
Shell脚本经典案例:文件的备份
C#使用NumericUpDown控件
网络层重点协议——IP协议
技能大赛训练题:域用户和组织单元的创建
For enterprises in the digital age, data governance is difficult, but it should be done
Error: npm ERR code EPERM
ECCV 2022 | 机器人的交互感知与物体操作
C#Assembly的使用
Selenium自动化测试之Selenium IDE
网络协议及相关技术详解
使用CompletableFuture进行异步处理业务
「面经分享」西北大学 | 字节 生活服务 | 一面二面三面 HR 面
Miller_Rabin 米勒拉宾概率筛【模板】
4.爬虫之Scrapy框架2数据解析&配置参数&数据持久化&提高Scrapy效率