[Numpy-discussion] setting the attributes of an array of object
Travis E. Oliphant
Tue Oct 16 11:17:29 CDT 2007
Sebastian Haase wrote:
> there is a way of doing this. As far as I know, you have to create
> your own "version of numpy arrays". E. g. try this:
> class myNumpy(numpy.ndarray):
> Then creating an instance as in
> a = myNumpy(otherNumpyArray)
> would make `a` behave just like any other array, except that you CAN
> attach attributes to it.
> Be carefull that some (many / most ?) operations on that array will
> return you a normal numpy array again.
> I don't understand the reasons behind all of this.
The __array_priority__ attribute determines who "wins" when two
different sub-classes are involved in an operation. The ndarray has a
priority of 0.0.
More information about the Numpy-discussion