当前位置:网站首页>Pytorch sharpening chapter | argmax and argmin functions
Pytorch sharpening chapter | argmax and argmin functions
2022-07-01 22:32:00 【51CTO】
One 、 Grammar format
Format 1 ( Only aim at argmax function ):
torch.argmax(input) → LongTensor
function :
Returns the indices of the maximum value of all elements in the input tensor.
namely : Returns the index corresponding to the maximum value of all elements in the input tensor ( Search by line ); If there are multiple identical values , Then return the index corresponding to the value encountered for the first time .
give an example :
In [28]: r=torch.tensor([[1,2,3,4,5],[6,7,8,9,10],[11,12,13,14,15]])
In [29]: torch.argmax(r)
Out[29]: tensor(14)
Format two :
[1]torch.argmax(input, dim=None, keepdim=False)
function :
Returns the indices of the maximum values of a tensor across a dimension.
- input( Tensor) – the input tensor. namely : Output tensor .
- dim( int) – the dimension to reduce. If
None
, the argmax of the flattened input is returned. namely : Dimension to reduce .
- keepdim( bool) – whether the output tensor has
dim
retained or not. Ignored if dim=None
. namely :
give an example :
In [30]: a = torch.randn(4, 4)
In [31]: a
Out[31]:
tensor([[ 1.4360, 0.6342, -0.5233, 0.4902],
[ 1.1998, -0.8644, 0.5244, 0.2690],
[ 0.0998, -1.5043, 0.1619, -1.4634],
[ 0.0992, -1.0843, -1.3829, 0.5790]])
In [32]: torch.argmax(a)
Out[32]: tensor(0)
In [33]: torch.argmax(a,dim=0)
Out[33]: tensor([0, 0, 1, 3])
In [34]: torch.argmax(a,dim=1)
Out[34]: tensor([0, 0, 2, 3])
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- about tensor(0) Output , The meaning is as follows :
The first 0 individual : 1.4360 | The first 1 individual : 0.6342 | The first 2 individual : -0.5233 | The first 3 individual : 0.4902 | The first 4 individual : 1.1998 | The first 5 individual : -0.8644 | The first 6 individual : 0.5244 | The first 7 individual : 0.2690 | The first 8 individual : 0.0998 | The first 9 individual : -1.5043 |
The first 10 individual : 0.1619 | The first 11 individual : -1.4634 | The first 12 individual : 0.0992 | The first 13 individual : -1.0843 | The first 14 individual : -1.3829 | The first 15 individual : 0.5790 |
- about tensor([0, 0, 1, 3]) Output , The meaning is as follows :
At this time , Each column is regarded as subscript from 0 To 3 An array of . Easy to see , Each column from left to right ( Array ) The maximum values in are :1.4360、0.6342、0.5244、0.5790, The subscripts in their corresponding one-dimensional array are 0、0、1、3, So we get the tensor tensor([0, 0, 1, 3]).
- about tensor([0, 0, 2, 3]) Output :
The meaning is easy to understand . Look horizontally from left to right, from top to bottom , Each row corresponds to an array , The subscripts left and right are 0、1、2、3. therefore , this 4 The maximum values in the arrays are 1.4360、1.1998、0.1619、1.3829, The subscripts in their corresponding one-dimensional array are 0、0、2、3, So we get the tensor tensor([0, 0, 2, 3]).
function :
[2]torch.argmin(input, dim=None, keepdim=False) → LongTensor
argmin function :Returns the indices of the minimum value(s) of the flattened tensor or along a dimension.
Understand something like the above argmax The second format of the function , Corresponding to dim=0 and dim=1, Return the tensor composed of the column direction array and the row direction array composed of the subscript corresponding to the minimum value in turn .
边栏推荐
- QT版本华睿相机的Demo程序实现
- Four methods of JS array splicing [easy to understand]
- mysql 学习笔记-优化之SQL优化
- [intelligent QBD risk assessment tool] Shanghai daoning brings you leanqbd introduction, trial and tutorial
- #yyds干货盘点# 解决名企真题:扭蛋机
- Spark interview questions
- [noip2013] building block competition [noip2018] road laying greed / difference
- One of the basic learning of function
- "The silk road is in its youth and looks at Fujian" is in the hot collection of works in the Fujian foreign youth short video competition
- 100年仅6款产品获批,疫苗竞争背后的“佐剂”江湖
猜你喜欢
Mysql——》索引存储模型推演
Aidl basic use
Significance and measures of security encryption of industrial control equipment
函数基本学习之一
Yan Rong looks at how to formulate a multi cloud strategy in the era of hybrid cloud
[NOIP2013]积木大赛 [NOIP2018]道路铺设 贪心/差分
BlocProvider 为什么感觉和 Provider 很相似?
详解ThreadLocal
Recent public ancestor (LCA) online practices
Talking from mlperf: how to lead the next wave of AI accelerator
随机推荐
Mysql——》Innodb存储引擎的索引
MySQL empties table data
Basic knowledge of ngnix
MQ learning notes
函数基本学习之一
[live broadcast review] the first 8 live broadcasts of battle code Pioneer have come to a perfect end. Please look forward to the next one!
Icml2022 | interventional contrastive learning based on meta semantic regularization
【juc学习之路第8天】Condition
MIT|256KB 内存下的设备上训练
LIS (longest ascending subsequence) problem that can be understood [easy to understand]
详解JMM
Airserver mobile phone third-party screen projection computer software
BlocProvider 为什么感觉和 Provider 很相似?
mysql 学习笔记-优化之SQL优化
【直播回顾】战码先锋首期8节直播完美落幕,下期敬请期待!
辅音和声母的区别?(声母与辅音的区别)
PHP reflective XSS, reflective XSS test and repair
PyTorch磨刀篇|argmax和argmin函数
按照功能对Boost库进行分类
Is PMP certificate really useful?