[Numpy-discussion] my derived ndarray class object loses its attribute after a transpose()

Pierre GM pgmdevlist at gmail.com
Sat Nov 24 11:50:36 EST 2007


> Is it correct to assume that  N.ndarray does *not* do it's own
> N.ndarray.__new__(**options) or so, that I would have to call ?
> (In other words: If I derive from N.ndarray I do not need to do a
> def __new__(**options):
>    N.ndarray.__new__(**options)
> , right?)

That'd work if ndarray.__new__ were accepting an extra dictionary of 
parameters, a la **options. This is not the case. So, following the example 
in the wiki, if you want to build an InfoArray with InfoArray(x,info={}), you 
will need a __new__method to process the argument "info" that ndarray does 
not recognize. 
True, you could first create your object, then fill in as needed, such as:
>>>x=InfoArray([1,2,3])
>>>x.info = {'name':'x'}

It looks less clear than 
>>>InfoArray([1,2,3], info= {'name':'x'}
don't you think ?



More information about the NumPy-Discussion mailing list