当前位置:网站首页>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 .
边栏推荐
- 100年仅6款产品获批,疫苗竞争背后的“佐剂”江湖
- plantuml介绍与使用
- Matlab traverses images, string arrays and other basic operations
- AirServer2022最新版功能介绍及下载
- 91.(cesium篇)cesium火箭发射模拟
- [noip2013] building block competition [noip2018] road laying greed / difference
- linux下清理系统缓存并释放内存
- The leader of the cloud native theme group of beacon Committee has a long way to go!
- 收到一封CTO来信,邀约面试机器学习工程师
- 【juc学习之路第9天】屏障衍生工具
猜你喜欢
对象内存布局
List announced | outstanding intellectual property service team in China in 2021
Microsoft, Columbia University | Godel: large scale pre training of goal oriented dialogue
Copy ‘XXXX‘ to effectively final temp variable
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
[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!
【juc学习之路第9天】屏障衍生工具
MySQL learning notes - SQL optimization of optimization
K-means based user portrait clustering model
详解JMM
随机推荐
工控设备安全加密的意义和措施
Indicator trap: seven KPI mistakes that it leaders are prone to make
In the past 100 years, only 6 products have been approved, which is the "adjuvant" behind the vaccine competition
Several ways of writing main function in C
The leader of the cloud native theme group of beacon Committee has a long way to go!
keras训练的H5模型转tflite
Unity 使用Sqlite
CSDN购买的课程从哪里可以进入
GaussDB(DWS)主动预防排查
MySQL series transaction log redo log learning notes
【juc学习之路第9天】屏障衍生工具
Interview question: what is the difference between MySQL's Union all and union, and how many join methods MySQL has (Alibaba interview question) [easy to understand]
GenICam GenTL 标准 ver1.5(4)第五章 采集引擎
Pytest collection (2) - pytest operation mode
pytest合集(2)— pytest运行方式
String type conversion BigDecimal, date type
小 P 周刊 Vol.11
AirServer2022最新版功能介绍及下载
Mask wearing detection method based on yolov5
高攀不起的希尔排序,直接插入排序