私は一般的に行っている操作を持っていますが、それを「ギザギザスライス」と呼んでいます。その本当の名前がわからないからです。例によって最もよく説明されています:
a = np.random.randn(50, 10)
entries_of_interest = np.random.randint(10, size = 50) # Vector of 50 indices between 0 and 9
# Now I want the values contained in each row of a at the corresponding index in "entries of interest"
jagged_slice_of_a = a[np.arange(a.shape[0]), entries_of_interest]
# jagged_slice_of_a is now a vector with 50 elements. Good.
唯一の問題は、このインデックス作成を行うのが少し面倒なことですa[np.arange(a.shape[0]), entries_of_interest]
(このためだけに "np.arange(a.shape[0])" を作成する必要があるのはばかげているようです)。:
これにはオペレーターのようなものが欲しいのですが、 は別の:
ことをします。この操作を行うためのより簡潔な方法はありますか?
ベストアンサー:
いいえ、ネイティブ numpy を使用するより良い方法はありません。必要に応じて、このためのヘルパー関数を作成できます。