I have an empty array:
empty = np.array([0, 0, 0, 0, 0])
an array of indices corresponding to positions in my array empty
ind = np.array([2, 3, 1, 2, 4, 2, 4, 2, 1, 1, 1, 2])
and an array of values
val = np.array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
I want to add the values in 'val' into 'empty' according to position given by 'ind'.
The non-vectorized solution is:
for i, v in zip(ind, val): maps[i] += v
>>> maps
[ 0. 4. 5. 1. 2.]
My actual arrays are multidimensional and loooong so i've got a NEED FOR SPEED I really want a vectorized solution, or a solution that is very fast.
Note this does not work:
maps[ind] += val
>>> maps
array([ 0., 1., 1., 1., 1.])
I'd be extra grateful for a solution that works in python 2.7, 3.5, 3.6 with no hiccups