[Numpy-discussion] Please help with subclassing numpy.ndarray
Mon Feb 5 10:32:22 CST 2007
On 2/4/07, Pierre GM <firstname.lastname@example.org> 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.
> Actually, yes:
> In the example given in http://scipy.org/Subclasses an attribute 'info' is
> defined from a class-generic one '__defaultinfo'. Just do the same thing with
> your 'edges'
> def __new__(cls,...)
> (H, edges) = numpy.histogramdd(..)
> cls.__defaultedges = edges
> def __array_finalize__(self, obj):
> if not hasattr(self, 'edges'):
> self.edges = self.__defaultedges
> That should the trick.
Thanks for clarifying that. I didn't understand what the
More information about the Numpy-discussion