[SciPy-User] Accumulation sum using indirect indexes
Tue Jan 31 16:26:14 CST 2012
This is the purpose of the group by NEP in NumPy. It is on the roadmap. In the mean time, you will need to either use Pandas group by or code something using indexing coupled with sum().
(on a mobile)
On Jan 31, 2012, at 2:34 PM, Alexander Kalinin <firstname.lastname@example.org> wrote:
> 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?
> SciPy-User mailing list
More information about the SciPy-User