I'm trying to do histrogram using numpy array indexing (without explicit iteration over array). Just to check if it works as expected I did following test:
import numpy as np
arr = np.zeros(10)
inds = np.array([1,2,3,1,3,5,3])
arr[inds] += 1.0
print(arr)
the result is
[ 0. 1. 1. 1. 0. 1. 0. 0. 0. 0.]
instead of
[ 0. 2. 1. 3. 0. 1. 0. 0. 0. 0.]
.
(i.e. it omits indexes which appear multiple times in index array)
I'm not sure if there is some reason for this behavior (perhaps to make these operation order independent and therefore easier to paralellize).
Is there any other way how to do this in numpy ?