I would like to ask you a quick question:
I am facing the opposite problem described here:
In short, I want to create a class Dummy(np.ndarra y) which returns a plain array whenever is sliced or viewed. I cannot figure out how.
I would really appreciate you help, here is a chunk of code, what is commented was an attempt which didn’t work.
Thanks a lot,
Jacopo
I am facing the opposite problem described here:
In short, I want to create a class Dummy(np.ndarra y) which returns a plain array whenever is sliced or viewed. I cannot figure out how.
I would really appreciate you help, here is a chunk of code, what is commented was an attempt which didn’t work.
Thanks a lot,
Jacopo
Code:
import numpy as np class Dummy(np.ndarray): def __del__(self): print "__del__" def __new__(cls, array): print "__new__" obj=array.view(cls) return obj def __array_finalize__(self, obj): print "__array_finalize__" #self=self.view(np.ndarray) #self=np.asarray(self) def __repr__(self): return "%s"%np.asarray(self) p=Dummy(np.ones(5)) print type(p)
Comment