[Numpy-discussion] question about ufuncs

Pierre GM pgmdevlist@gmail....
Sun Feb 1 18:33:45 CST 2009


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...


More information about the Numpy-discussion mailing list