[Numpy-discussion] question about ufuncs
Darren Dale
dsdale24@gmail....
Sun Feb 1 18:39:04 CST 2009
On Sun, Feb 1, 2009 at 7:33 PM, Pierre GM <pgmdevlist@gmail.com> wrote:
>
> On Feb 1, 2009, at 6:32 PM, Darren Dale wrote:
> >
> >
> > Is there an analog to __array_wrap__ for preprocessing arrays on
> > their way *into* a ufunc? For example, it would be nice if one could
> > do something like:
> >
> > numpy.sin([1,2,3]*arcseconds)
> >
> > where we have the opportunity to inspect the context, convert the
> > Quantity to units of radians, and then actually call the ufunc. Is
> > this possible, or does one have to reimplement such functions?
>
> Just an idea: look at the code for numpy.ma ufuncs (in numpy.ma.core).
> By defining a few classes for unary, binary and domained functions,
> you could probably do what you want, without having to recode all the
> functions by hand.
> Another idea would be to define some specific __mul__ or __rmul__
> rules for your units, so that the list would be transformed into a
> UnitArray...
I have pretty good implementations of the arithmetic operators, so
([1,2,3]*m)*([4,5,6]*J) already works. numpy.multiply and numpy.sqrt needed
help with array_wrap. I'll study your stuff in ma, thanks for the pointer.
Darren
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20090201/87b3dfb9/attachment.html
More information about the Numpy-discussion
mailing list