[SciPy-User] Can I create a 3 argument UFunc easily?
Thu Jun 10 12:26:49 CDT 2010
On Tue, Jun 8, 2010 at 7:27 PM, Robert Kern <email@example.com> wrote:
> On Tue, Jun 8, 2010 at 18:46, John Salvatier <firstname.lastname@example.org> wrote:
>> I would like to make a 3 argument UFunc that finds the weighted average of
>> two of the arguments using the 3rd argument as the weight. This way, the
>> .accumulate method of the ufunc can be used as an exponentially weighted
>> moving average function.
>> Unfortunately I am not very familiar with the Numpy C API, so I was hoping
>> to use the Cython hack for making UFuncs
>> (http://wiki.cython.org/MarkLodato/CreatingUfuncs). However, looking at the
>> UFunc C API doc
>> (http://docs.scipy.org/doc/numpy/reference/c-api.ufunc.html), it looks like
>> numpy only has 2 argument "generic functions". Is there a simple way to
>> create a "generic function" that takes 3 arguments that will still work with
>> accumulate? Is there another way to create the sort of UFunc I want?
> While you can make n-argument ufuncs (scipy.special has many of them),
> .accumulate() only works for 2-argument ufuncs.
> All in all, it's a lot easier and more performant to simply code up an
> EWMA in C rather than "tricking" the general ufunc machinery into
> achieving a specific effect.
> Robert Kern
> "I have come to believe that the whole world is an enigma, a harmless
> enigma that is made terrible by our own mad attempt to interpret it as
> though it had an underlying truth."
> -- Umberto Eco
> SciPy-User mailing list
I can point out a couple EWMA implementations present in
scikits.timeseries (C) and pandas (Cython), that you could co-opt if
they do what you want. I'm sure there are others out there
More information about the SciPy-User