[Numpy-discussion] put with increment ?

Jon Wright wright at esrf.fr
Thu Apr 29 04:28:19 EDT 2010


Hello everyone,

Is there a 'numpy' efficient way to do the following loop:

for i, v in indices, values:
     total[ i ] += v


The behaviour is like numpy.put, but instead of overwriting the array 
element, it is incremented. Currently I have a little C extension which 
does the job, but I'm lazy to fix it up for all the various dtypes etc. 
Am I missing a more general way? I have repeated values in indices, so that:

total[indices]+=values

... does not give the result I'm after.

Thanks

Jon




More information about the NumPy-Discussion mailing list