[Numpy-discussion] how add new attribute to a numpy array object ?
haase at msg.ucsf.edu
Sat Jul 22 22:39:19 CDT 2006
I have a (medical) image file.
I wrote a nice interface based on memmap using numarray.
The class design I used was essentially to return a numarray array
object with a new "custom" attribute giving access to special
information about the base file.
Now with numpy I noticed that a numpy object does not allow adding new
attributes !! (How is this ? Why ?)
Travis already suggested (replying to one of my last postings) to create
a new sub class of numpy.ndarray.
But how do I initialize an object of my new class to be "basically
identically to" an existing ndarray object ?
Normally I could do
a.__class__ = B
BUT I get this error:
#>>> a.__class__ = B
Traceback (most recent call last):
File "<input>", line 1, in ?
TypeError: __class__ assignment: only for heap types
What is a "heap type" ? Why ? How can I do what I want ?
More information about the Numpy-discussion