[Numpy-discussion] numpy subclass
Jacopo
jacopo.pecci@gmail....
Thu Jul 23 12:13:26 CDT 2009
I am facing the opposite problem described here:
http://docs.scipy.org/doc/numpy/user/basics.subclassing.html
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.
I would really appreciate your help, here is a chunk of code, what is commented
was an attempt which didn’t work out.
Thanks a lot,
Jacopo
p.s. I can be more wordy in explain the problem i just
dont want to overwhelm you.
import numpy as np
class Dummy(np.ndarray):
def __new__(cls, array):
obj=array.view(cls)
return obj
def __array_finalize__(self, obj):
#self=self.view(np.ndarray)
#self=np.asarray(self)
d=Dummy(np.ones(5))
d2=d[:3]
print type(d2) # I wish this was np.array
More information about the NumPy-Discussion
mailing list