[Numpy-discussion] put with increment ?

Robert Kern robert.kern@gmail....
Thu Apr 29 11:20:39 CDT 2010

On Thu, Apr 29, 2010 at 03:28, Jon Wright <wright@esrf.fr> wrote:
> 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?

total = np.bincount(indices, values)

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco

More information about the NumPy-Discussion mailing list