[Numpy-discussion] Please help with subclassing numpy.ndarray

Jeremy Conlin jeremit0@gmail....
Sun Feb 4 19:22:44 CST 2007


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,…):
    # Some stuff here
    H, edges = numpy.histogramdd(…)
    return H


This sets H as the instance of my object.  I would also like to have
edges be an attribute of MyClass.  I can't do:

self.edges = edges

because the object hasn't been instantiated yet.  Can someone show me
how I can also keep the information from the variable edges?
Thanks,
Jeremy


More information about the Numpy-discussion mailing list