当前位置:网站首页>Torch in pytoch Sort() and torch Argsort() function parsing
Torch in pytoch Sort() and torch Argsort() function parsing
2022-07-18 08:10:00 【cv_ lhp】
One . torch.sort() Function analysis
1. The website links
torch.sort(), As shown in the figure below :
2. torch.sort() Function analysis
torch.sort(input, dim=- 1, descending=False, stable=False, *, out=None)
Input input, stay dim Sort dimensions , The default is dim=-1 Sort the last dimension ,descending Indicates whether to arrange in descending order , The default is False, Output the sorted value and the corresponding value in the original input imput Subscript in
3. The code for
3.1 dim = -1 Indicates that the elements in each row are sorted in ascending order ,descending=False Indicates ascending sort
x = torch.randn(3, 4)
sorted, indices = torch.sort(x)
x,sorted,indices
The output is as follows :
(tensor([[-1.3864, 0.5811, -0.1056, -0.3237],
[-0.2136, -1.4806, 0.4986, 0.9382],
[-0.2820, 0.1171, -0.3983, -0.8061]]),
tensor([[-1.3864, -0.3237, -0.1056, 0.5811],
[-1.4806, -0.2136, 0.4986, 0.9382],
[-0.8061, -0.3983, -0.2820, 0.1171]]),
tensor([[0, 3, 2, 1],
[1, 0, 2, 3],
[3, 2, 0, 1]]))
3.2 dim = 0 Indicates that the elements in each column are sorted in ascending order ,descending=False Indicates ascending sort
x = torch.randn(3, 4)
sorted, indices = torch.sort(x,dim=0)
x,sorted,indices
The output is as follows :
(tensor([[ 0.7081, 1.0502, 2.0434, -0.2592],
[ 1.2052, 0.8809, 0.5771, 1.2978],
[-1.5873, -0.4808, -2.1774, -0.2503]]),
tensor([[-1.5873, -0.4808, -2.1774, -0.2592],
[ 0.7081, 0.8809, 0.5771, -0.2503],
[ 1.2052, 1.0502, 2.0434, 1.2978]]),
tensor([[2, 2, 2, 0],
[0, 1, 1, 2],
[1, 0, 0, 1]]))
3.3 dim = 0 Means to sort the elements in each column in descending order ,descending=True Represents a descending sort
x = torch.randn(3, 4)
sorted, indices = torch.sort(x,dim=0,descending=True)
x,sorted,indices
The output is as follows :
(tensor([[ 0.9142, -0.2178, 0.5602, 2.3951],
[-0.6977, 0.4915, 0.3988, 0.6406],
[ 0.4880, 1.1646, -0.3466, 0.5801]]),
tensor([[ 0.9142, 1.1646, 0.5602, 2.3951],
[ 0.4880, 0.4915, 0.3988, 0.6406],
[-0.6977, -0.2178, -0.3466, 0.5801]]),
tensor([[0, 2, 0, 0],
[2, 1, 1, 1],
[1, 0, 2, 2]]))
3.4 dim = 1 Means to sort the elements in each row in descending order ,descending=True Represents a descending sort
x = torch.randn(3, 4)
sorted, indices = torch.sort(x,dim=1,descending=True)
x,sorted,indices
The output is as follows :
(tensor([[-0.3048, -1.9915, -0.0888, 0.3881],
[ 1.0677, -1.3520, 0.2944, -0.0772],
[-0.9409, -0.9630, -0.7946, 1.4400]]),
tensor([[ 0.3881, -0.0888, -0.3048, -1.9915],
[ 1.0677, 0.2944, -0.0772, -1.3520],
[ 1.4400, -0.7946, -0.9409, -0.9630]]),
tensor([[3, 2, 0, 1],
[0, 2, 3, 1],
[3, 2, 0, 1]]))
Two .torch.argsort() Function analysis
1. The website links
torch.argsort(), As shown in the figure below :
2. torch.argsort() Function analysis
Usage follow the above torch.sort() The function is the same , The difference is torch.argsort() Return only the original input corresponding to the sorted value input The subscript , namely torch.sort() Back to indices
3. The code for
dim = 1 Means to sort the elements in each row in descending order ,descending=True Represents a descending sort , The output result is the original input corresponding to the returned sorted value input The subscript indices
x = torch.randn(3, 4)
indices = torch.argsort(x,dim=1,descending=True)
x,indices
The output is as follows :
(tensor([[-0.6069, -0.9252, -0.9177, 0.6997],
[ 0.3245, -0.0665, 0.4600, 0.0722],
[-1.0662, 2.2669, -0.1171, -0.9208]]),
tensor([[3, 0, 2, 1],
[2, 0, 3, 1],
[1, 2, 3, 0]]))
边栏推荐
- 394.字符串解码·栈
- Matlab:图像增强 imageDataAugmenter() 的用法
- GeoServer complete tutorial
- 蓝鲸配置框架
- CTSI foundation reserve transparency report - July 2022
- fftshift有什么用?MATLAB做FFT后为什么还要fftshift?
- Difference between shape parameter and scale parameter in probability density function
- 數百億數據壓縮至 600GB,TDengine 落地協鑫能科移動能源平臺
- LDAP介绍
- Matlab: usage of split dataset spliteachlabel()
猜你喜欢

Pytoch distributed training

Qiu Zhao took 6 offers and summarized more than 20 categories of 1100 interview questions, including answer analysis

LDAP introduction

GeoServer complete tutorial

Pytorch中torch.repeat()函数解析

Matlab:trainingoptions() explain training options in detail

J9数字科普:Web3.0很遥远?不它已经来了

数百亿数据压缩至 600GB,TDengine 落地协鑫能科移动能源平台

Pytorch中的广播机制(Broadcast)

338. Bit counting · dynamic programming
随机推荐
3-6月面经总结,200多页真题笔记和详解(含核心考点及6家大厂)
Matlab calculates the integral of normal function, and the quantile corresponding to the integral
745. Prefix and suffix search
Sorting out knowledge points of queue (single queue) and deque (double ended queue)
每日一题·1252.奇数值单元格的数目·模拟优化
在创建生成WIFI二维码手机扫码链接
Matlab:拆分数据集 splitEachLabel() 的用法
(零六)Flask有手就行——配置静态文件
Pytorch中torch.argmax()函数解析
oracle跨网断转发如何解决?
(high frequency interview questions) computer network
SAR图像:拟合杂波时常用的分布
Today, another chip IPO came out of Shenzhen Huaqiangbei
每日一题·1217.玩筹码·贪心
One question per day · 735 Planetary collision · stack simulation
Matlab:交换矩阵的两行(列)
(zero six) flask is OK if you have hands - configure static files
Software architecture and design (IX) -- component based architecture
【无标题】慢 SQL 分析与优化
Is CICC wealth securities a formal securities company? Is it safe to open an account