Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
ソートされていないリストがあり、 を使用してソートするとしnp.sortます。numpy を使用して元のリストからソートされたリストのインデックスを取得する方法はありますか?
np.sort
最も簡単な方法は、配列に位置インデックスを追加してから、2 次元配列を並べ替えることです。これにより、並べ替えられたデータと元の位置インデックスの両方が同時に得られます。
(ソートされたデータではなく)インデックスのみが必要な場合は、argsortを使用します。
>>> from numpy import array >>> arr = array([10, 5, 80, 20, 70, 18]) >>> arr.argsort() array([1, 0, 5, 3, 4, 2])