[Numpy-discussion] numpy subclass

Pierre GM pgmdevlist at gmail.com
Thu Jul 23 13:30:23 EDT 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):
           obj=array.view(cls)
           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