I'm trying to subclass numpy.complex64
in order to make use of the way numpy stores the data, (contiguous, alternating real and imaginary part) but use my own __add__
, __sub__
, ... routines.
My problem is that when I make a numpy.ndarray
, setting dtype=mysubclass
, I get a numpy.ndarray
with dtype='numpy.complex64'
in stead, which results in numpy not using my own functions for additions, subtractions and so on.
Example:
import numpy as np
class mysubclass(np.complex64):passa = mysubclass(1+1j)
A = np.empty(2, dtype=mysubclass)print type(a)
print repr(A)
Output:
<class '__main__.mysubclass'>
array([ -2.07782988e-20 +4.58546896e-41j, -2.07782988e-20 +4.58546896e-41j], dtype=complex64)'
Does anyone know how to do this?
Thanks in advance - Soren