当前位置:网站首页>【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()方法说明
边栏推荐
- Solution for browser hijacking by hao360
- Shang Silicon Valley-JVM-Memory and Garbage Collection (P1~P203)
- All-round visual monitoring of the Istio microservice governance grid (microservice architecture display, resource monitoring, traffic monitoring, link monitoring)
- Network layer key protocol - IP protocol
- Usage of += in C#
- 技能大赛训练题:交换机虚拟化练习
- The operator,
- 20.nn.Module
- 爱可可AI前沿推介(7.31)
- 1小时直播招募令:行业大咖干货分享,企业报名开启丨量子位·视点
猜你喜欢

技能大赛训练题:MS15_034漏洞验证与安全加固

ECCV2022: Recursion on Transformer without adding parameters and less computation!

Edge Cloud Explained in Simple Depth | 4. Lifecycle Management

Reasons and solutions for Invalid bound statement (not found)

Open Inventor 10.12 Major Improvements - Harmony Edition

LeetCode·304竞赛·6132·使数组中所有元素都等于零·模拟·哈希

新款现代帕里斯帝预售开启,安全、舒适一个不落

C#高级--委托

20.nn.Module

The use of C# control CheckBox
随机推荐
JSP中如何借助response对象实现页面跳转呢?
技能大赛训练题:交换机虚拟化练习
Sliding window method to segment data
LeetCode·每日一题·1161.最大层内元素和·层次遍历
232层3D闪存芯片来了:单片容量2TB,传输速度提高50%
Shang Silicon Valley-JVM-Memory and Garbage Collection (P1~P203)
推荐系统-召回阶段-2013:DSSM(双塔模型)【Embedding(语义向量)召回】【微软】
VU 非父子组件通信
Spark Learning: Add Custom Optimization Rules for Spark Sql
LeetCode rotate array
IDEA连接MySQL数据库并使用数据
Linux bash: redis-server: command not found
技能大赛dhcp服务训练题
selenium被反爬了怎么办?
20.nn.Module
Miller_Rabin 米勒拉宾概率筛【模板】
【redis】发布和订阅消息
IDEA connects to MySQL database and uses data
LeetCode·304竞赛·6132·使数组中所有元素都等于零·模拟·哈希
DELL SC compellent 康贝存储系统怎么抓取配置信息