numpy.loadtxt无法读取带复数的文件 [英] numpy.loadtxt does not read file with complex numbers
本文介绍了numpy.loadtxt无法读取带复数的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用以下格式读取具有复数的文件:
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)
但这给了我以下错误:
TypeError: complex() argument must be a string or a number, not 'bytes'
我该怎么做才能解决这个问题?
What could I do to solve this problem ?
非常感谢您的帮助
推荐答案
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)
这篇关于numpy.loadtxt无法读取带复数的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文