Tuesday, March 29, 2011

Why can't numpy do duplicate index assignment

AG

I want to do drizzling with numpy. It should be trivial, but it's impossible (without a for loop, afaik) instead.


In [2]: a = array([1,1,2,2])

In [3]: b = arange(5)

In [4]: b[a] += 1

In [5]: b
Out[5]: array([0, 2, 3, 3, 4])

In [6]: # but b should really be:

In [7]: b[a] += 1

In [8]: b
Out[8]: array([0, 3, 4, 3, 4])

1 comment:

Adam said...

answer: numpy.bincount.

Also, http://code.google.com/p/agpy/source/browse/trunk/AG_image_tools/drizzle.py