[Numpy-discussion] nonuniform scatter operations

Nathan Bell wnbell@gmail....
Tue Sep 30 00:38:57 CDT 2008

On Sun, Sep 28, 2008 at 4:15 PM, Geoffrey Irving <irving@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@gmail.com

More information about the Numpy-discussion mailing list