[Numpy-discussion] how add new attribute to a numpy array object ?
Kevin Jacobs <jacobs@bioinformed.com>
bioinformed at gmail.com
Sun Jul 23 12:02:09 CDT 2006
On 7/22/06, Sebastian Haase <haase at msg.ucsf.edu> wrote:
>
> Normally I could do
> class B(N.ndarray):
> pass
> a=N.arange(10)
> 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 ?
Assigning to __class__ makes sense for objects that allocate a dictionary
for storage of attributes or have slots allocated to hold the values. The
heap type error is due to a missing flag in the class definition and could
be corrected. However, it may not be the best thing to do. Calling
B(array) is certainly safer, although a bit more expensive.
-Kevin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20060723/20de75dd/attachment.html
More information about the Numpy-discussion
mailing list