[SciPy-User] Accumulation sum using indirect indexes
Alexander Kalinin
alec.kalinin at gmail.com
Tue Jan 31 15:34:28 EST 2012
Hello!
I use SciPy in computer graphics applications. My task is to calculate
vertex normals by averaging faces normals. In other words I want to
accumulate vectors with the same ids. For example,
ids = numpy.array([0, 1, 1, 2])
n = numpy.array([ [0.1, 0.1, 0.1], [0.1, 0.1, 0.1], [0.1, 0.1, 0.1], [0.1,
0.1 0.1] ])
I need result:
nv = ([ [0.1, 0.1, 0.1], [0.2, 0.2, 0.2], [0.1, 0.1, 0.1]])
The most simple code:
nv[ids] += n
does not work, I know about this. For 1D arrays I use numpy.bincount(...)
function. But this function does not work for 2D arrays.
So, my question. What is the best way calculate accumulation sum for 2D
arrays using indirect indexes?
Sincerely,
Alexander
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20120131/b70c891b/attachment.html>
More information about the SciPy-User
mailing list