[Numpy-discussion] subclassing ndaray

Travis Oliphant oliphant at ee.byu.edu
Mon Feb 27 11:38:03 EST 2006


Stefan van der Walt wrote:

>If I understand correctly, the __array_finalize__ method should copy
>all meta data from the parent object to the child.  In other words, I
>might have something like:
>
>def __init__(self, ...):
>	self.v = 3
>
>def __array_finalize__(self, parent):
>	self.v = parent.v
>
>I do not want to do something like
>
>def __array_finalize__(self, parent):
>	self.v = 3
>
>Because then, every time I do an operation on my array, self.v will be
>reset.  Shouldn't array_finalize look for such methods/properties and copy
>them automatically? 
>
You need to set up __array_finalize__ to do that.  I did not want to do 
that for every sub-class because different things are required for 
different sub classes. 

So, this seems like a workable compromise.  It should work a bit better 
now that I've changed it so that __array_finalize__ is called on every 
sub-class creation.  If there is no "parent" then parent will be None.

-Travis





More information about the NumPy-Discussion mailing list