当前位置:网站首页>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
边栏推荐
- MySQL基础合集
- 阿里云回应用户注册信息泄露事件
- Opencv reports an error. Expected PTR < CV:: UMAT > for argument '% s'‘
- 学会打字后的思考
- 【SQL】字符串系列2:将一个字符串根据特定字符分拆成多行
- "Meta function" of tidb 6.0: what is placement rules in SQL?
- Come in and teach you how to solve the problem of port occupation
- Bracket matching -- [implementation of one-dimensional array]
- Express③(使用Express编写接口、跨域有关问题)
- Cmake project under vs2019: calculating binocular parallax using elas method
猜你喜欢

On IRP from the perspective of source code

What about laptop Caton? Teach you to reinstall the system with one click to "revive" the computer

Latex formula

MySQL数据库常识之储存引擎

Deep analysis of C language pointer (Part I)

GO語言開發天天生鮮項目第三天 案例-新聞發布系統二

Preliminary understanding of cache elimination algorithm (LRU and LFU)

Common commands of MySQL in Linux

MySQL基础合集

Vscode download speed up
随机推荐
常用60类图表使用场景、制作工具推荐
PHP的Laravel与Composer部署项目时常见问题
JS arrow function user and processing method of converting arrow function into ordinary function
Keywords static, extern + global and local variables
MySQL基础合集
Mysql database common sense storage engine
41. 缺失的第一个正数
Unity animation creates sequence frame code and generates animationclip
Unity solves Z-fighting
Come in and teach you how to solve the problem of port occupation
Zhongchuang storage | how to choose a useful distributed storage cloud disk
Unity ECS dots notes
电脑越用越慢怎么办?文件误删除恢复方法
Centralized record of experimental problems
Resolve the error - error identifier 'attr_ id‘ is not in camel case camelcase
Lunch on the 23rd day at home
Prim、Kruskal
CUDA, NVIDIA driver, cudnn download address and version correspondence
[SQL] string series 2: split a string into multiple lines according to specific characters
go defer