I'm trying to read a file (generated with Fortran) with complex numbers into Python.
Say, after using a = f1.readline().split( )
, I get the following value for a
:
a = ['(4.471719725275173E-003,2.163649191486555E-002)']
If I do
b = np.complex(a[0])
it produces an error
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-4-cff25069e279> in <module>()
----> 1 b = np.complex(a[0])
ValueError: complex() arg is a malformed string
I tried to do this based on the fact that numpy
seems to support Fortran notation (Reading fortran double precision format into python). Is there an equivalent function for complex numbers?
If not, what would be the best way to proceed (rather than using different delimiters in the split( )
call and reconstruct the complex number by hand).