Home  >  Article  >  Backend Development  >  python topN method to get the largest N number or the smallest N number

python topN method to get the largest N number or the smallest N number

不言
不言Original
2018-06-04 16:01:553621browse

This article mainly introduces the method of python topN to get the largest N number or the smallest N number. It has a certain reference value. Now I share it with you. Friends in need can refer to it

is as follows:

##

import numpy as np
a = np.array([1,4,3,5,2])
b = np.argsort(a)
print(b)

##print result[0 4 2 1 3]

Explain that a[0] is the smallest and a[3] is the largest

a[0]<a[4]<a[2]<a[1]<a[3]

The above is the detailed content of python topN method to get the largest N number or the smallest N number. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn