[Numpy-discussion] custom accumlators

Tim Hochberg tim.hochberg at ieee.org
Fri Jan 5 14:22:47 EST 2007

Matt Knox wrote:
> I made a post about this a while ago on the scipy-user mailing list, but I didn't receive much of a response so I'm just throwing it out there again (with more detail) in case it got overlooked.
> Basically, I'd like to be able to do accumulate operations with custom functions. numpy.vectorize does not seem to provide an accumulate method with the functions it returns. 
Note that if you are looking for speed, numpy.vectorize is probably not 
what you are looking for even if it did work for this sort of stuff.

> I'm hoping I don't have to write ufuncs in C to accomplish this, but I fear that may the case. Either way, it would be nice to know if it can, or cannot be done in an easy manner.
> I have lots of examples of where this kind of thing is useful, but I'll just outline two for now.


It is not obvious how to write these using numpy's primitives. You might 
want to look into one of psyco, pyrex or weave. Psyco's probably the 
easiest, but will get you the smallest (although still large) speed 
gain, if you use psyco there are some tricks I could suggest for 
speeding it up. Pyrex is probably the most polished, but I haven't used 
it with numpy so I can't comment on how natural that is.


More information about the NumPy-Discussion mailing list