[Numpy-discussion] Incrementing with advanced indexing: why don't repeated indexes repeatedly increment?

Robert Cimrman cimrman3@ntc.zcu...
Wed Jun 6 12:14:32 CDT 2012


On 06/06/2012 06:35 PM, Robert Kern wrote:
> On Wed, Jun 6, 2012 at 4:52 PM, Robert Cimrman<cimrman3@ntc.zcu.cz>  wrote:
>
>> Yes (in that thread), but it applies also adding/assembling vectors into a
>> global vector - this is just x[idx] += vals. I linked that discussion as that
>> was recent enough for me to recall it, but there were other.
>>
>> Anyway, my point was that a having a function with the "adding" semantics in
>> NumPy would be handy.
>
> x += numpy.bincount(idx, vals, minlength=len(x))
>

Nice! Looking at the C source, it seems it should be pretty efficient for this 
task.

r.


More information about the NumPy-Discussion mailing list