当前位置:网站首页>【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()方法说明
边栏推荐
- 爱可可AI前沿推介(7.31)
- Four ways to clear the float and its principle understanding
- What should I do if selenium is reversed?
- selenium被反爬了怎么办?
- leetcode:2032. 至少在两个数组中出现的值
- VU 非父子组件通信
- Even if the image is missing in a large area, it can also be repaired realistically. The new model CM-GAN takes into account the global structure and texture details
- Text similarity calculation (Chinese and English) detailed explanation of actual combat
- Solution for browser hijacking by hao360
- 技能大赛训练题:ftp 服务攻防与加固
猜你喜欢
hyperf的启动源码分析(二)——请求如何到达控制器
C# control ToolStripProgressBar usage
IDEA如何运行web程序
49.【拷贝构造函数与重载】
LeetCode·每日一题·1161.最大层内元素和·层次遍历
Spark Learning: Add Custom Optimization Rules for Spark Sql
AI cocoa AI frontier introduction (7.31)
AWS implements scheduled tasks - Lambda+EventBridge
IDEA connects to MySQL database and uses data
深度剖析 Apache EventMesh 云原生分布式事件驱动架构
随机推荐
ERROR: Failed building wheel for osgeo
C# control ListView usage
hyperf的启动源码分析(二)——请求如何到达控制器
Sliding window method to segment data
LeetCode rotate array
Invalid bound statement (not found)出现的原因和解决方法
numpy矩阵和向量的保存与加载,以及使用保存的向量进行相似度计算
技能大赛训练题: 子网掩码划分案例
Selenium IDE for Selenium Automation Testing
pytorch gpu版本安装最新
Tortoise speed by "template"
报错:npm ERR code EPERM
Detailed explanation of network protocols and related technologies
LeetCode·每日一题·1161.最大层内元素和·层次遍历
机器学习模型验证:被低估的重要一环
网络协议及相关技术详解
抓住金三银四的尾巴,解锁程序员面试《刷题神器》
滑窗法切分数据
动作捕捉系统用于柔性机械臂的末端定位控制
Network layer key protocol - IP protocol