Sturla Molden wrote:
>>Good point. I guess I thought the OP had tried that already. It turns
>>out it works fine, too.
>>
>>The __array_finalize__ is useful if you want the attribute to be carried
>>around when arrays are created automatically internally (after math
>>operations for example).
>>
> Good point. I guess I thought the OP had tried that already. It turns
> out it works fine, too.
>
> The __array_finalize__ is useful if you want the attribute to be carried
> around when arrays are created automatically internally (after math
> operations for example).
I too may be missing so
Reggie Dugard wrote:
>On Wed, 2007-02-07 at 14:36 -0700, Travis Oliphant wrote:
>
>
>>Sturla Molden wrote:
>>
>>
>>
def __new__(cls,...)
...
(H, edges) = numpy.histogramdd(..)
cls.__defaultedges = edges
def __array_finalize__(self, obj):
if not hasa
On Wed, 2007-02-07 at 14:36 -0700, Travis Oliphant wrote:
> Sturla Molden wrote:
>
> >>def __new__(cls,...)
> >> ...
> >>(H, edges) = numpy.histogramdd(..)
> >>cls.__defaultedges = edges
> >>
> >>def __array_finalize__(self, obj):
> >>if not hasattr(self, 'edges'):
> >>sel
Sturla Molden wrote:
>>def __new__(cls,...)
>> ...
>>(H, edges) = numpy.histogramdd(..)
>>cls.__defaultedges = edges
>>
>>def __array_finalize__(self, obj):
>>if not hasattr(self, 'edges'):
>>self.edges = self.__defaultedges
>>
>>
>
>So in order to get an instance attr
> I don't pretend to know all the inner workings of subclassing, but I
> don't think that would work, given the following output:
> In [6]: x+y
> This is where __array_finalize__ is called
> Out[6]: MyArray([4, 5, 6])
Why is not __new__ called for the return value of x + y? Does it call
__new__
> Yes using __init__ to set an instance attribute is the Pythonic way to
> do this. However, I calculate/create the data in __new__. The data
> is unavailable to __init__.
The signatures of __new__ and __init__ is:
def __new__(cls, *args, **kwds)
def __init__(self, *args, **kwds)
If __new__ h
On 2/6/07, Sturla Molden <[EMAIL PROTECTED]> wrote:
>
> > def __new__(cls,...)
> > ...
> > (H, edges) = numpy.histogramdd(..)
> > cls.__defaultedges = edges
> >
> > def __array_finalize__(self, obj):
> > if not hasattr(self, 'edges'):
> > self.edges = self.__defaultedges
>
On Tue, Feb 06, 2007 at 01:06:37PM +0100, Sturla Molden wrote:
>
> > def __new__(cls,...)
> > ...
> > (H, edges) = numpy.histogramdd(..)
> > cls.__defaultedges = edges
> >
> > def __array_finalize__(self, obj):
> > if not hasattr(self, 'edges'):
> > self.edges = self.__de
> def __new__(cls,...)
> ...
> (H, edges) = numpy.histogramdd(..)
> cls.__defaultedges = edges
>
> def __array_finalize__(self, obj):
> if not hasattr(self, 'edges'):
> self.edges = self.__defaultedges
So in order to get an instance attribute, one has to temporarily defi
On 2/5/07, Pierre GM <[EMAIL PROTECTED]> wrote:
> On Monday 05 February 2007 11:32:22 Jeremy Conlin wrote:
> > Thanks for clarifying that. I didn't understand what the
> > __array_finalize__ did.
>
> That means I should clarify some points on the wiki, then.
> A good exercise is to put some tempor
On Monday 05 February 2007 11:32:22 Jeremy Conlin wrote:
> Thanks for clarifying that. I didn't understand what the
> __array_finalize__ did.
That means I should clarify some points on the wiki, then.
A good exercise is to put some temporary comments in your code in __new__ and
__array_finalize
On 2/4/07, Pierre GM <[EMAIL PROTECTED]> wrote:
> On Sunday 04 February 2007 20:22:44 Jeremy Conlin wrote:
> > I have subclassed the numpy.ndarray object, but need some help setting
> > some attributes. I have read http://scipy.org/Subclasses but it
> > doesn't provide the answer I am looking for.
On Sunday 04 February 2007 20:22:44 Jeremy Conlin wrote:
> I have subclassed the numpy.ndarray object, but need some help setting
> some attributes. I have read http://scipy.org/Subclasses but it
> doesn't provide the answer I am looking for.
Actually, yes:
In the example given in http://scipy.or
I have subclassed the numpy.ndarray object, but need some help setting
some attributes. I have read http://scipy.org/Subclasses but it
doesn't provide the answer I am looking for.
I create an instance of the class in my __new__ method as:
import numpy
class MyClass(numpy.ndarray):
__new__(self,
15 matches
Mail list logo