-1
假設你有下面的代碼NumPy的高級索引:同一指數多次使用的+ =
a = np.ones(8)
pos = np.array([1, 3, 5, 3])
a[pos] # returns array([ 1., 1., 1., 1.]), where the 2nd and 4th el are the same
a[pos] +=1
最後一條指令返回
array([ 1., 2., 1., 2., 1., 2., 1., 1.])
但我想,超過同一指標來分配總結,以獲取
array([ 1., 2., 1., 3., 1., 2., 1., 1.])
有人已經經歷過這種情況嗎?
由於
看看'np.add.at'。 – Divakar
謝謝,這似乎在做伎倆:) – diningphil
@Divakar如果你想寫一個答案,我會刪除我的社區維基。 –