当前位置:网站首页>[Pytorch] torch.argmax() usage
[Pytorch] torch.argmax() usage
2022-07-31 14:07:00 【Rain or shine】
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,Eliminate the highest dimension of the tensor,也就是说将b张量为([3 ,3,4])变为([3,4]);
同理,dim=1,Eliminate the second highest dimension,也就是说将b张量为([3,3 ,4])变为([3,4]);dim=2,Eliminate the third highest dimension,也就是说将b张量为([3,3,4 ])变为([3,3]);以此类推.dim=-1表示张量维度的最低维度 -2表示张量的倒数第二维度,-3表示倒数第三维度.
下一篇:
【Pytorch】F.softmax()方法说明
边栏推荐
- leetcode:485.最大连续 1 的个数
- All-round visual monitoring of the Istio microservice governance grid (microservice architecture display, resource monitoring, traffic monitoring, link monitoring)
- 232层3D闪存芯片来了:单片容量2TB,传输速度提高50%
- C# control ToolStripProgressBar usage
- jvm 一之 类加载器
- C# List Usage List Introduction
- 技能大赛训练题:交换机虚拟化练习
- For enterprises in the digital age, data governance is difficult, but it should be done
- mysql8, starttime的下一个值作为endtime的上一个值?
- ML、DL、CV常见的问题整理
猜你喜欢
技能大赛训练题:域用户和组织单元的创建
图像大面积缺失,也能逼真修复,新模型CM-GAN兼顾全局结构和纹理细节
MySQL [aggregate function]
技能大赛训练题:登录安全加固
【蓝桥杯选拔赛真题46】Scratch磁铁游戏 少儿编程scratch蓝桥杯选拔赛真题讲解
Open Inventor 10.12 Major Improvements - Harmony Edition
“听我说谢谢你”还能用古诗来说?清华搞了个“据意查句”神器,一键搜索你想要的名言警句...
MySQL【聚合函数】
3.爬虫之Scrapy框架1安装与使用
Shang Silicon Valley-JVM-Memory and Garbage Collection (P1~P203)
随机推荐
The latest complete code: Incremental training using the word2vec pre-training model (two loading methods corresponding to two saving methods) applicable to various versions of gensim
[Blue Bridge Cup Trial Question 46] Scratch Magnet Game Children's Programming Scratch Blue Bridge Cup Trial Question Explanation
拥塞控制,CDN,端到端
C语言基础练(九九乘法表)与打印不同星号图案
I summed up the bad MySQL interview questions
C# using ComboBox control
redhat/openssl生成自签ca证书并使用
leetcode: 485. Maximum number of consecutive 1s
ECCV 2022 | 机器人的交互感知与物体操作
LeetCode·304竞赛·6132·使数组中所有元素都等于零·模拟·哈希
How to quickly split and merge cell data in Excel
为什么 wireguard-go 高尚而 boringtun 孬种
Open Inventor 10.12 重大改进--和谐版
LeetCode旋转数组
Six Stones Programming: No matter which function you think is useless, people who can use it will not be able to leave, so at least 99%
The Selenium IDE of the Selenium test automation
IDEA connects to MySQL database and uses data
The JVM a class loader
ICML2022 | 面向自监督图表示学习的全粒度自语义传播
Detailed guide to compare two tables using natural full join in SQL