当前位置:网站首页>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 .
边栏推荐
- "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
- PyTorch磨刀篇|argmax和argmin函数
- 首席信息官对高绩效IT团队定义的探讨和分析
- 业务可视化-让你的流程图'Run'起来
- Mysql——》Innodb存储引擎的索引
- Fundamentals - IO intensive computing and CPU intensive computing
- [commercial terminal simulation solution] Shanghai daoning brings you Georgia introduction, trial and tutorial
- Chapter 9 Yunji datacanvas company has been ranked top 3 in China's machine learning platform market
- Recent public ancestor (LCA) online practices
- 高攀不起的希尔排序,直接插入排序
猜你喜欢
EasyExcel 复杂数据导出
Do you want to make up for the suspended examination in the first half of the year? Including ten examinations for supervision engineers, architects, etc
Mysql——》Innodb存储引擎的索引
Significance and measures of security encryption of industrial control equipment
企业架构与项目管理的关联和区别
Application of real estate management based on 3D GIS
Indicator trap: seven KPI mistakes that it leaders are prone to make
“丝路正青春 风采看福建”在闽外籍青年短视频大赛火热征集作品中
【juc学习之路第9天】屏障衍生工具
News classification based on LSTM model
随机推荐
基于三维GIS的不动产管理应用
The correct way to set the bypass route
[ecological partner] Kunpeng system engineer training
An operation tool used by we media professionals who earn 1w+ a month
从MLPerf谈起:如何引领AI加速器的下一波浪潮
A debugging to understand the slot mechanism of redis cluster
In the past 100 years, only 6 products have been approved, which is the "adjuvant" behind the vaccine competition
焱融看 | 混合云时代下,如何制定多云策略
linux下清理系统缓存并释放内存
Mysql——》MyISAM存储引擎的索引
Why must digital transformation strategies include continuous testing?
Using closures to switch toggle by clicking a button
MQ learning notes
News classification based on LSTM model
灵动微 MM32 多路ADC-DMA配置
多种智能指针
名单揭晓 | 2021年度中国杰出知识产权服务团队
Medium pen test questions: flip the string, such as ABCD, print out DCBA
Business visualization - make your flowchart'run'up
Spark interview questions