[Numpy-discussion] numpy subclass

Pierre GM pgmdevlist@gmail....
Thu Jul 23 12:30:23 CDT 2009

On Jul 23, 2009, at 1:13 PM, Jacopo wrote:
> 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.

Easy enough for slices:
     class Dummy(np.ndarray):
         def __new__(cls, array):
           return obj
         def __getslice__(self, i, j):
             return np.ndarray.__getslice__(self, i, j).view(np.ndarray)

For views, the problem needs to be better described: why would you  
want to get just a basic ndarray ?

More information about the NumPy-Discussion mailing list