Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
値が大きい上位K件の配列インデックスを取得
#探す対象リスト:my_arrayはnumpy
#例:上位3件
K = 3
# ソートはされていない上位k件のインデックス
unsorted_max_indices = np.argpartition(-my_array, K)[:K]
# 上位k件の値
y = my_array[unsorted_max_indices]
# 大きい順にソートし、インデックスを取得
indices = np.argsort(-y)
# 類似度上位k件のインデックス
max_k_indices = unsorted_max_indices[indices]
@naoyashiga
Copy link
Author

naoyashiga commented Apr 28, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment