当前位置:网站首页>Pytorch selects the first k maximum (minimum) values and their indexes in the data
Pytorch selects the first k maximum (minimum) values and their indexes in the data
2022-04-23 20:48:00 【NuerNuer】
Select the maximum value and its index , Everyone knows how to use max(),argmax() function .
So how to return to the previous k It's a maximum , This is when we calculate topK Accuracy is necessary :
stay torch in , We can use sort Function to implement :
a, idx1 = torch.sort(data, descending=True)#descending by alse, Ascending , by True, Descending
idx = idx1[:k]
Return:
a: Ordered data
idx1: The index corresponding to the sorted data
So just set k Size , You can intercept the front k An index with a maximum value . If the data here is tensor Then use torch, if list or ndarray, It can be used numpy.
版权声明
本文为[NuerNuer]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210545522718.html
边栏推荐
- Cmake project under vs2019: calculating binocular parallax using elas method
- 【SQL】字符串系列2:将一个字符串根据特定字符分拆成多行
- Common problems in deploying projects with laravel and composer for PHP
- 3-5通过XSS获取cookie以及XSS后台管理系统的使用
- Unity Odin ProgressBar add value column
- How to learn software testing? Self study or training? After reading this article, you will understand
- Fastdfs mind map
- Is qiniu school useful and is the recommended securities account safe
- Leetcode 1351. Negative numbers in statistical ordered matrices
- On IRP from the perspective of source code
猜你喜欢
Prim、Kruskal
Commande dos pour la pénétration de l'Intranet
Gsi-ecm digital platform for engineering construction management
Devaxpress report replay: complete the drawing of conventional two-dimensional report + histogram + pie chart
PHP的Laravel与Composer部署项目时常见问题
Deep analysis of C language function
Preliminary understanding of cache elimination algorithm (LRU and LFU)
Mysql database common sense storage engine
A login and exit component based on token
一些接地气的话儿
随机推荐
Leetcode 709, convert to lowercase
Go限制深度遍历目录下文件
On the three paradigms of database design
Win 11K in 100 days, super complete learning guide for job transfer test
MySQL stored procedures and functions
Solve importerror: cannot import name 'imread' from 'SciPy misc‘
启牛学堂有用吗,推荐的证券账户是否安全
MySQL进阶之表的增删改查
ros功能包内自定义消息引用失败
Leetcode-279-complete square number
Recommended usage scenarios and production tools for common 60 types of charts
3-5通过XSS获取cookie以及XSS后台管理系统的使用
高薪程序员&面试题精讲系列91之Limit 20000加载很慢怎么解决?如何定位慢SQL?
又一款数据分析神器:Polars 真的很强大
Addition, deletion, modification and query of MySQL advanced table
Fastdfs mind map
GO語言開發天天生鮮項目第三天 案例-新聞發布系統二
Use of node template engine
笔记本电脑卡顿怎么办?教你一键重装系统让电脑“复活”
Leetcode 1337. Row K with the weakest combat effectiveness in the matrix