【发布时间】:2017-10-24 15:09:24
【问题描述】:
非常不言自明(我在 Windows 上):
>>> import sys, numpy
>>> a = numpy.int_(sys.maxint)
>>> int(a).__class__
<type 'long'>
>>> int(int(a)).__class__
<type 'int'>
为什么调用int 一次给我long,而调用它两次给我int?
这是错误还是功能?
【问题讨论】:
-
在 Ubuntu 14.04 LTS 上使用 Python 2.7.6 和 numpy 1.8.2 以及在 Ubuntu 16.04 LTS 上使用 Python 2.7.12 numpy 1.11.0 也给了我一个 int。
-
我提到的结果是在 Linux 上。我刚刚在 Windows 上使用 Numpy 1.12.1 进行了测试,我确实重现了你的结果。对于 2147483646,它给出一个
int,但对于 2147483647,它是一个long。 -
我在使用
numpy.int64(9223372036854775807)的Linux 上遇到同样的错误,它被转换为long,而小于1 的错误被转换为int。 -
@AshwiniChaudhary:与问题无关;查看我的编辑。
标签: python python-2.7 numpy int long-integer