[Numpy-discussion] custom accumlators

Travis Oliphant oliphant at ee.byu.edu
Fri Jan 5 18:52:09 EST 2007


Tim Hochberg wrote:

>A. M. Archibald wrote:
>
>
>[SNIP]
>  
>
>>Really it would be nice if what vectorize() returned were effectively
>>a ufunc, supporting all the various operations we might want from a
>>ufunc (albeit inefficiently). This should not be difficult, but I am
>>not up to writing it this evening.
>>  
>>    
>>
>You might want to look at frompyfunc:
>
>        def expmave2(x, k):
>            def expmave_sub(a, b):
>                return a + k * (b - a)
>            return np.frompyfunc(expmave_sub, 2, 1).accumulate(x)
>
>
>  
>
Thanks, Tim. 

This is what I was going to mention.   Vectorize is built on top of 
frompyfunc which lets you create "object-array" ufuncs from python 
functions.

All ufuncs have an accumluate method.

-Travis






More information about the NumPy-Discussion mailing list