[Numpy-discussion] nonuniform scatter operations

Nathan Bell wnbell at gmail.com
Tue Sep 30 01:38:57 EDT 2008


On Sun, Sep 28, 2008 at 4:15 PM, Geoffrey Irving <irving at naml.us> wrote:
>
> Thanks.  That works great.  A slightly cleaner version is
>
>    X += coo_matrix((Y, (K, zeros_like(K)))).sum(axis=1)
>
> The next question is: is there a similar way that generalizes to the
> case where X is n by 3 and Y is m by 3 (besides the obvious loop over
> range(3), that is)?
>

You could flatten the arrays and make a single matrix that implemented
the operation.  I'd stick with the loop over range(3) though, it's
more readable and likely to be as fast or faster than flattening the
arrays yourself.

-- 
Nathan Bell wnbell at gmail.com
http://graphics.cs.uiuc.edu/~wnbell/



More information about the NumPy-Discussion mailing list