“OverflowError: Python int too large to convert to C long” on windows but not mac

前端 未结 3 1382
逝去的感伤
逝去的感伤 2020-12-03 16:43

I am running the exact same code on both windows and mac, with python 3.5 64 bit.

On windows, it looks like this:

>>> import numpy as np
&g         


        
3条回答
  •  萌比男神i
    2020-12-03 17:29

    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 "", line 1, in 
    OverflowError: Python int too large to convert to C long
    

    You can confirm this by checking:

    >>> import sys
    >>> sys.maxsize
    2147483647
    

    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))
    

提交回复
热议问题