[Numpy-discussion] making arithmetic operations compatible with ndarray

T.J. Alumbaugh talumbau@llnl....
Sun Sep 14 03:09:43 CDT 2008


Hi,

I'm wondering if someone can give me a tip on how to modify my Python  
type to work with certain arithmetic operations with ndarray.  The  
actual operation I would like is as follows:

ndarrayRef += myObj

where myObj is a reference to an object of a user defined Python type  
(with array-type data as one of its members).  I need a solution that  
does not involve my type inheriting from the ndarray class.  A fast  
solution would be great, but is not required, so a pure Python  
solution would be fine.  My user defined type does use the Numpy C  
API to expose its data as an ndarray (with  
PyArray_SimpleNewFromData), but that involves a function call to  
return that reference.  I'm hoping there is a solution that is along  
the lines of 'define these three member functions on your type and  
the object will be numpy-ish enough to do the job.'  Any ideas?  Thanks,

-T.J. Alumbaugh
talumbau@llnl.gov



More information about the Numpy-discussion mailing list