当前位置:网站首页>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 .
边栏推荐
- 焱融看 | 混合云时代下,如何制定多云策略
- Sonic云真机学习总结6 - 1.4.1服务端、agent端部署
- 从零开始学 MySQL —数据库和数据表操作
- What is the difference between PMP and NPDP?
- Training on the device with MIT | 256Kb memory
- 【juc学习之路第9天】屏障衍生工具
- Difference and use between require and import
- The leader of the cloud native theme group of beacon Committee has a long way to go!
- [ecological partner] Kunpeng system engineer training
- 对象内存布局
猜你喜欢
随机推荐
按照功能对Boost库进行分类
[noip2013] building block competition [noip2018] road laying greed / difference
详解ThreadLocal
In the past 100 years, only 6 products have been approved, which is the "adjuvant" behind the vaccine competition
linux下清理系统缓存并释放内存
业务可视化-让你的流程图'Run'起来
Several ways of writing main function in C
Clean up system cache and free memory under Linux
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
Electron学习(三)之简单交互操作
[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!
Mysql——》索引存储模型推演
从零开始学 MySQL —数据库和数据表操作
#yyds干货盘点# 解决名企真题:扭蛋机
Application of real estate management based on 3D GIS
K-means based user portrait clustering model
AirServer2022最新版功能介绍及下载
首席信息官对高绩效IT团队定义的探讨和分析
Business visualization - make your flowchart'run'up
详解JMM









![快乐数[环类问题之快慢指针]](/img/37/5c94b9b062a54067a50918f94e61ea.png)