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

前端 未结 3 1390
逝去的感伤
逝去的感伤 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条回答
  •  被撕碎了的回忆
    2020-12-03 17:25

    Could anyone help explain why

    In Python 2 a python "int" was equivalent to a C long. In Python 3 an "int" is an arbitrary precision type but numpy still uses "int" it to represent the C type "long" when creating arrays.

    The size of a C long is platform dependent. On windows it is always 32-bit. On unix-like systems it is normally 32 bit on 32 bit systems and 64 bit on 64 bit systems.

    or give a solution for the code on windows? Thanks so much!

    Choose a data type whose size is not platform dependent. You can find the list at https://docs.scipy.org/doc/numpy/reference/arrays.scalars.html#arrays-scalars-built-in the most sensible choice would probably be np.int64

提交回复
热议问题