[SciPy-User] subclassing ndarray : i want slice to return > ndarray, not subclass
Thu May 24 05:40:25 CDT 2012
> > Subclassing ndarray is a very tricky business -- I did it once and
> > regretted having done it for years, because there's so much you can't do
> > etc.. You're almost certainly better off with embedding an array as an
> > attribute, and then forward properties etc. to it.
> Yes, it's almost always the wrong thing...
I've sub-classes numpy.ndarray in some of my personal code, so I'm just
hoping to understand why this is the wrong choice before I dig the
hole any deeper.
So it's only wrong because it's hard to do right, and you can't do certain things? (which things?)
If you want a object to act mostly like a numpy.ndarray, making a sub-class *should* be the right answer.
Because isn't forwarding lookups to a wrapped class just a re-implementation of the sub-classing mechanism?
Isn't it also tricky to get that "wrapping subclassing" right?
If you're going to sub-class something, it would be nice to use the built in sub-class machinery, for clarity... etc...
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the SciPy-User