[Numpy-discussion] custom accumlators

Tim Hochberg tim.hochberg at ieee.org
Fri Jan 5 17:57:31 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)
>
>
> It's amazing what you find when you dig around.
>   
I guess that this should have an astype since this comes back as an 
object array. It would be cool if there was a way to have it return 
certain types, just for efficiency reasons, but that would require 
actual work on someones part.

-tim
>   




More information about the NumPy-Discussion mailing list