当前位置:网站首页>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
边栏推荐
- Resolve the eslint warning -- ignore the warning that there is no space between the method name and ()
- Fastdfs思维导图
- Communication between RING3 and ring0
- Centralized record of experimental problems
- 高薪程序员&面试题精讲系列91之Limit 20000加载很慢怎么解决?如何定位慢SQL?
- Win 11K in 100 days, super complete learning guide for job transfer test
- JS arrow function user and processing method of converting arrow function into ordinary function
- Common commands of MySQL in Linux
- Queue template code
- MySQL基础之写表(创建表)
猜你喜欢
What about laptop Caton? Teach you to reinstall the system with one click to "revive" the computer
GO語言開發天天生鮮項目第三天 案例-新聞發布系統二
High paid programmer & interview question series 91 limit 20000 loading is very slow. How to solve it? How to locate slow SQL?
Leetcode 994, rotten orange
电脑越用越慢怎么办?文件误删除恢复方法
LeetCode 116. Populate the next right node pointer for each node
Cmake project under vs2019: calculating binocular parallax using elas method
3-5通过XSS获取cookie以及XSS后台管理系统的使用
Reentrant function
Linux中,MySQL的常用命令
随机推荐
How to learn software testing? Self study or training? After reading this article, you will understand
go reflect
Commande dos pour la pénétration de l'Intranet
Unity asset import settings
bounding box iou
笔记本电脑卡顿怎么办?教你一键重装系统让电脑“复活”
Thinking after learning to type
GO語言開發天天生鮮項目第三天 案例-新聞發布系統二
How to do after winning the new debt? Is it safe to open an account online
启牛学堂有用吗,推荐的证券账户是否安全
go array
Unity Odin ProgressBar add value column
亚马逊和Epic将入驻,微软应用商城向第三方开放
C# 知识
Rust更适合经验较少的程序员?
Deep analysis of C language pointer (Part I)
Express③(使用Express编写接口、跨域有关问题)
Gsi-ecm digital platform for engineering construction management
Matlab: psychtoolbox installation
matplotlib. Pyplot partition drawing