python - numpy.loadtxt 不读取包含复数的文件

标签 python numpy

我正在尝试读取一个包含以下形式的复数的文件:

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

我使用以下代码读取文件:

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'

我能做些什么来解决这个问题?

非常感谢您的帮助

最佳答案

这似乎是旧版本 numpy (Issue) 中的错误。要么将你的 numpy 更新到他们的 github 存储库的最新版本,要么使用函数 numpy.genfromtxt()。

c.complex = np.genfromtxt('data.dat', delimiter='\t', dtype=np.complex128)

关于python - numpy.loadtxt 不读取包含复数的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32498199/

相关文章:

python - 以 tensorflow 变量作为输入的 keras 前向传递

python - 无法打印类的输出

python - TensorFlow 中张量值的条件赋值

python - 从 python 上传 blob 到 BlobStore 在 http 上返回 500

python - 在 Nginx 上使用 uWSGI 部署 Pyramid 的问题

python - 如何访问 numpy 数组中索引满足某些条件的所有元素?

python - 自举估计方差为何减少的数学解释

python - 计算 CFD 网格中点之间的距离

python - 使用python增加图像中特定像素的亮度

python - 编写类时扩展或覆盖文档字符串