[Numpy-discussion] numpy subclass
Thu Jul 23 15:33:53 CDT 2009
> In short, I want to create a class Dummy, inherited from np.ndarray, which
> returns a plain array whenever an instance is sliced or viewed. I cannot figure
> out how.
> class Dummy(np.ndarray):
> def __new__(cls, array):
> return obj
> def __array_finalize__(self, obj):
I think the problem here is that self.view(np.ndarray) returns another
object, which is of type ndarray, pointing to the data in self. The
problem being that you have not changed the object pointed to by
``self``, you've only made the local variable ``self`` point to
something different that will then be thrown away when your new
``self`` variable goes out of scope.
What you want to do here, is to modify the class of ``self`` inplace;
I don't know how to do that...
More information about the NumPy-Discussion