[NumPy-Tickets] [NumPy] #1872: Problem with matrix(dtype='complex') in Python 2.5

NumPy Trac numpy-tickets@scipy....
Sun Jun 19 21:36:39 CDT 2011

#1872: Problem with matrix(dtype='complex') in Python 2.5
 Reporter:  asmeurer  |       Owner:  somebody   
     Type:  defect    |      Status:  new        
 Priority:  normal    |   Milestone:  Unscheduled
Component:  Other     |     Version:  1.6.0      
 Keywords:            |  
 If I put the following in a file called numpyfloattest.py

 import numpy

 class A(object):
     def __float__(self):
         return 2.0
     def __complex__(self):
         return 5.0j

 a = A()

 print numpy.matrix([[a]], dtype='complex')

 I get

 $python2.5 numpyfloattest.py
 [[ 2.+0.j]]
 $python2.6 numpyfloattest.py
 [[ 0.+5.j]]
 $python2.7 numpyfloattest.py
 [[ 0.+5.j]]

 In other words, for some reason, in Python 2.5 it is calling float() on
 the data even though the dtype is complex.  As you can imagine, this
 causes problems when the data is an object that represents a complex
 number.  In particular, this bug is causing problems with SymPy code that
 tries to convert the SymPy matrix [[0, -I], [I, 0]] to a numpy matrix (I
 is sympy.I, i.e., sqrt(-1)).   See

Ticket URL: <http://projects.scipy.org/numpy/ticket/1872>
NumPy <http://projects.scipy.org/numpy>
My example project

More information about the NumPy-Tickets mailing list