2019-04-22
阅读量:
456
如何得到数组的n个最大值
# np.random.shuffle(x), Modify a sequence in-place
# np.argsort(x) Returns the indices that would sort an array.
# np.argpartition(x)
Z = np.arange(10)
np.random.shuffle(Z)
n = 2
print Z[np.argsort(Z)[-n:]] # slow
print Z[np.argpartition(-Z,n)[:n]] # fast
[8 9]
[9 8]






评论(0)


暂无数据