Home > Article > Backend Development > python topN method to get the largest N number or the smallest N number
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!