问题描述
我正在Windows和Mac上运行完全相同的代码,并使用python 3.5 64位.
I am running the exact same code on both windows and mac, with python 3.5 64 bit.
在Windows上,它看起来像这样:
On windows, it looks like this:
>>> import numpy as np
>>> preds = np.zeros((1, 3), dtype=int)
>>> p = [6802256107, 5017549029, 3745804973]
>>> preds[0] = p
Traceback (most recent call last):
File "<pyshell#13>", line 1, in <module>
preds[0] = p
OverflowError: Python int too large to convert to C long
但是,此代码在我的Mac上正常工作.任何人都可以帮助解释原因或为Windows上的代码提供解决方案吗?非常感谢!
However, this code works fine on my mac. Could anyone help explain why or give a solution for the code on windows? Thanks so much!
推荐答案
一旦您的数字大于sys.maxsize
,就会收到该错误:
You'll get that error once your numbers are greater than sys.maxsize
:
>>> p = [sys.maxsize]
>>> preds[0] = p
>>> p = [sys.maxsize+1]
>>> preds[0] = p
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: Python int too large to convert to C long
您可以通过以下方法确认这一点:
You can confirm this by checking:
>>> import sys
>>> sys.maxsize
2147483647
要更精确地获取数字,请不要在后台传递使用有界C整数的int类型.使用默认的float:
To take numbers with larger precision, don't pass an int type which uses a bounded C integer behind the scenes. Use the default float:
>>> preds = np.zeros((1, 3))
这篇关于"OverflowError:Python int太大,无法转换为C long"在Windows而非Mac上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!