[Numpy-discussion] subclassing float64 (and friends)
Stefan van der Walt
stefan at sun.ac.za
Fri Jan 5 06:22:58 EST 2007
On Wed, Jan 03, 2007 at 05:12:40PM -0600, eric jones wrote:
> Thanks for the update. For now, I'll try doing what I need to by
> sub-classing float. But, I'm gonna miss __array_finalize__ :-).
Looks like r3493 is intended to fix this. The 'view' method works
now, but I still see
In [2]: import numpy as N
In [3]: x = N.float64(12)
In [4]: class Floaty(N.float64):
...: def __new__(subclass,data):
...: return data.view(subclass)
In [6]: Floaty(x)
Out[6]: 12.0
In [7]: type(Floaty(x))
Out[7]: <type 'numpy.float64'>
versus
In [8]: class Ary(N.ndarray):
...: def __new__(subclass,data):
...: return data.view(subclass)
In [9]: Ary(N.array([1]))
Out[9]: Ary([1])
In [10]: type(Ary(N.array([1])))
Out[10]: <class '__main__.Ary'>
Cheers
Stéfan
More information about the NumPy-Discussion
mailing list