[Numpy-discussion] numpy.complex* functions do not call the __complex__ method

jason-sage@creativetra... jason-sage@creativetra...
Thu Sep 25 01:03:27 CDT 2008

In creating an array of type numpy.complex128, I'm having problems 
passing in Sage types that should be considered complex numbers since 
they implement the standard __complex__ method.  However, numpy doesn't 
recognize that.  Here's a minimal example:

In [1]: class MyNum:
   ...:     def __complex__(self):
   ...:         return complex(1,3)

In [2]: import numpy

In [3]: a=MyNum()

In [4]: complex(a)
Out[4]: (1+3j)

In [5]: numpy.complex128(a)
<type 'exceptions.AttributeError'>        Traceback (most recent call last)

/home/jason/download/numpy/numpy-1.1.0/src/numpy/<ipython console> in 

<type 'exceptions.AttributeError'>: MyNum instance has no attribute 

This is with numpy 1.1.  Is this a bug, or is this by design?



More information about the Numpy-discussion mailing list