热线电话:13121318867

登录
2019-04-22 阅读量: 457
如何得到数组的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.0000
0
关注作者
收藏
评论(0)

发表评论

暂无数据