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'):
self.edges =
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 hasattr(self, 'edges'):
self.edges
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).
I too
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 define it
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.__defaultedges
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
So in order to
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__ for
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 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 temporary