Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

numpy.loadtxt does not read file with complex numbers

Tags:

python

numpy

I am trying to read a file with complex numbers in the form :

data.dat

1.5795219122457646E-11-3.852906516379872E-15i   -3.5949335665378405E-12-1.626143709108086E-15i
-6.720365121161621E-15-5.377186331212649E-17i   -3.736251476362349E-15-3.0190920417856674E-17i

I use the following code to read the file :

import numpy as np

c_complex = np.loadtxt('data.dat', delimiter='\t', dtype=np.complex128)

But it gives me the following error :

TypeError: complex() argument must be a string or a number, not 'bytes'

What could I do to solve this problem ?

Thank you very much for your help

like image 705
Anthony Lethuillier Avatar asked Aug 05 '26 18:08

Anthony Lethuillier


1 Answers

This seems to have been a bug in older versions of numpy (Issue). Either update your numpy to the latest version of their github repository or use the function numpy.genfromtxt().

c.complex = np.genfromtxt('data.dat', delimiter='\t', dtype=np.complex128)
like image 79
Dencrash Avatar answered Aug 07 '26 09:08

Dencrash