当前位置:网站首页>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
边栏推荐
- How to learn software testing? Self study or training? After reading this article, you will understand
- MySQL 存储过程和函数
- Addition, deletion, modification and query of advanced MySQL data (DML)
- Psychological formula for converting RGB to gray value
- Imitation Baidu map realizes the three buttons to switch the map mode by automatically shrinking the bottom
- go array
- Bash script learning -- for loop traversal
- Come in and teach you how to solve the problem of port occupation
- Lunch on the 23rd day at home
- laravel 发送邮件
猜你喜欢

MySQL basic collection

【SQL】字符串系列2:将一个字符串根据特定字符分拆成多行

3-5通过XSS获取cookie以及XSS后台管理系统的使用

41. The first missing positive number

Common problems in deploying projects with laravel and composer for PHP

Deep analysis of C language pointer (Part I)

Another data analysis artifact: Polaris is really powerful

Leetcode 542, 01 matrix

MySQL基础合集

內網滲透之DOS命令
随机推荐
unity 功能扩展
DOS command of Intranet penetration
Identifier CV is not defined in opencv4_ CAP_ PROP_ FPS; CV_ CAP_ PROP_ FRAME_ COUNT; CV_ CAP_ PROP_ POS_ Frames problem
Solution: NPM err! code ELIFECYCLE npm ERR! errno 1
bounding box iou
UKFslam
Is qiniu school useful and is the recommended securities account safe
An error occurs when the addressable assets system project is packaged. Runtimedata is null
3-5 obtaining cookies through XSS and the use of XSS background management system
Awk example skills
go map
wait、waitpid
Keywords static, extern + global and local variables
Deep analysis of C language function
Vulnhub DC: 1 penetration notes
Unity solves Z-fighting
CUDA, NVIDIA driver, cudnn download address and version correspondence
Elastic box model
6-5 string - 2 String copy (assignment) (10 points) the C language standard function library includes the strcpy function for string copy (assignment). As an exercise, we write a function with the sam
How to learn software testing? Self study or training? After reading this article, you will understand