gpt4 book ai didi

python - 使用 numpy genfromtxt 从混合数据类型文件导入大整数

转载 作者:太空宇宙 更新时间:2023-11-04 03:56:19 24 4
gpt4 key购买 nike

我有一个格式的文件:

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com