当前位置:网站首页>【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()方法说明
边栏推荐
- Usage of += in C#
- The use of C# control CheckBox
- 1小时直播招募令:行业大咖干货分享,企业报名开启丨量子位·视点
- 49.【拷贝构造函数与重载】
- Save and load numpy matrices and vectors, and use the saved vectors for similarity calculation
- mysql8, starttime的下一个值作为endtime的上一个值?
- AI cocoa AI frontier introduction (7.31)
- Reasons and solutions for Invalid bound statement (not found)
- leetcode:2032. 至少在两个数组中出现的值
- 报错IDEA Terminated with exit code 1
猜你喜欢

C# using NumericUpDown control

Invalid bound statement (not found)出现的原因和解决方法

ADS communicate with c #

AWS implements scheduled tasks - Lambda+EventBridge

操作符详解

“听我说谢谢你”还能用古诗来说?清华搞了个“据意查句”神器,一键搜索你想要的名言警句...

Resolved (pymysqL connect to the database error) pymysqL. Err. ProgrammingError: (1146, "Table" test. Students' doesn 't exist ")

代码随想录笔记_哈希_454四数相加II

Error: npm ERR code EPERM

Edge Cloud Explained in Simple Depth | 4. Lifecycle Management
随机推荐
How to quickly split and merge cell data in Excel
C# control StatusStrip use
golang-gin - graceful restart
Open Inventor 10.12 重大改进--和谐版
Shell脚本经典案例:文件的备份
Miller_Rabin Miller Rabin probability sieve [template]
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
VU 非父子组件通信
The use of C# control CheckBox
[Niu Ke brush questions - SQL big factory interview questions] NO3. E-commerce scene (some east mall)
20.nn.Module
抓住金三银四的尾巴,解锁程序员面试《刷题神器》
LeetCode·304竞赛·6132·使数组中所有元素都等于零·模拟·哈希
golang-gin-pprof-使用以及安全问题
已解决(pymysqL连接数据库报错)pymysqL.err.ProgrammingError: (1146,“Table ‘test.students‘ doesn‘t exist“)
AI cocoa AI frontier introduction (7.31)
【蓝桥杯选拔赛真题46】Scratch磁铁游戏 少儿编程scratch蓝桥杯选拔赛真题讲解
C# List Usage List Introduction
For enterprises in the digital age, data governance is difficult, but it should be done
SetoolKit使用指南