[Numpy-discussion] metadata and metabehavior for arrays (for scipy.base or Numeric3)

Colin J. Williams cjw at sympatico.ca
Thu Apr 7 05:57:36 CDT 2005


konrad.hinsen at laposte.net wrote:

> On Apr 7, 2005, at 10:06, David M. Cooke wrote:
>
>> Hmm, I had misread your previous code. Here it is again, made more
>> specific, and I'll assume this function lives in the ndarray package
>> (as there is more than one package that defines ufuncs)
>
>
> At the moment, there is one in Numeric and one in numarray. The Python 
> API of both is nearly or fully identical.
>
>> The thing is obj.__ufunc__ must understand about the *particular*
>> object cos: the ndarray one. I was thinking more along the lines of
>
>
> No, it must only know the interface. In most cases, it would do 
> something like
>
>     class MyArray:
>         def __ufunc__(self, ufunc):
>             return MyArray(apply(ufunc, self.data))
>
>> obj.__ufunc__('cos'), where the name is passed instead.
>
>
> That's also an interesting option. It would require the implementing 
> class to choose an appropriate function from an appropriate module. 
> Alternatively, it would work if ufuncs were also accessible as methods 
> on array objects.
>
Yes, perhaps with a slightly different name (say Cos vs cos) to 
distinguish between methods and functions.  Since they don't require 
arguments, the methods would not require parentheses.

Colin W.




More information about the Numpy-discussion mailing list