当前位置:网站首页>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
边栏推荐
- Deep analysis of C language pointer (Part I)
- 41. 缺失的第一个正数
- MySQL 存储过程和函数
- Syntax Error: TypeError: this. getOptions is not a function
- 又一款数据分析神器:Polars 真的很强大
- Leetcode 542, 01 matrix
- Is qiniu school useful and is the recommended securities account safe
- LeetCode-279-完全平方数
- Solve the Chinese garbled code of URL in JS - decoding
- Unity solves Z-fighting
猜你喜欢

Recommended usage scenarios and production tools for common 60 types of charts

Write table of MySQL Foundation (create table)

Deep analysis of C language function

PHP的Laravel与Composer部署项目时常见问题

MySQL基础之写表(创建表)

Come in and teach you how to solve the problem of port occupation

Matlab matrix index problem

Some grounded words

Prim、Kruskal

JS arrow function user and processing method of converting arrow function into ordinary function
随机推荐
IOT 设计与开发
Resolve the error - error identifier 'attr_ id‘ is not in camel case camelcase
mmap、munmap
C knowledge
Learn to C language fourth day
Unity Odin ProgressBar add value column
Gsi-ecm digital platform for engineering construction management
Learn to C language fourth day
打新债中签以后怎么办,网上开户安全吗
C# 知识
Flex layout
Come in and teach you how to solve the problem of port occupation
GO語言開發天天生鮮項目第三天 案例-新聞發布系統二
Leetcode-279-complete square number
On IRP from the perspective of source code
Go language development Daily Fresh Project Day 3 Case - Press Release System II
中创存储|想要一个好用的分布式存储云盘,到底该怎么选
[SQL] string series 2: split a string into multiple lines according to specific characters
MySQL数据库常识之储存引擎
Vscode download speed up