adding an attribute to an nd-array

Robert Kern robert.kern at gmail.com
Thu Oct 19 10:54:42 CDT 2006


Travis Oliphant wrote:
> I just learned about how to allow built-ins to have attributes assigned 
> to their instances.   It's actually pretty easy because of Python 
> support for it --- but it comes at a cost.  You have to add a dictionary 
> to the PyArrayObject structure, create that dictionary when the ndarray 
> is allocated, and set the tp_dictoffset in the TypeObject structure to 
> its location in PyArrayObject.   It takes 4 lines of code with the cost of
> creating a new dictionary for every ndarray.
> 
> I don't think the extra bytes for every ndarray object are worth it, 
> given how easy it is to sub-class and create your own ndarray that can 
> have attributes attached.    What are others opinions.

I'd say leave it off. Many uses of that feature will require custom 
__array_finalize__ methods anyways.

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


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642




More information about the Numpy-discussion mailing list