我有一个格式如下的文件:
1 2.5264 24106644528 astring
我想导入数据。我正在使用:
>>> numpy.genfromtxt('myfile.dat',dtype=None)
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
numpy.genfromtxt('myfile.dat',skip_header=27,dtype=None)
File "C:\Python27\lib\site-packages\numpy\lib\npyio.py", line 1691, in genfromtxt
output = np.array(data, dtype=ddtype)
OverflowError: Python int too large to convert to C long
我检查了我的(32 位)系统上的最大整数:
>>> import sys
>>> sys.maxint
2147483647
有没有办法提高整数限制?或者我可以用另一种方式解决导入问题(不在文件中的所有整数后面添加“.0”)吗?
最佳答案
意识到我可以做到这一点:
>>> numpy.genfromtxt('myfile.dat',dtype=['i4','f8','f8','a14'])
array((1, 2.5264, 24106644528.0, 'astring'),
dtype=[('f0', '<i4'), ('f1', '<f8'), ('f2', '<f8'), ('f3', 'S14')])
关于python - 使用 numpy genfromtxt 从混合数据类型文件导入大整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18253450/