<p>numpy.int64 不是 int 的实例</p>

创建于 2013-01-27  ·  4评论  ·  资料来源: numpy/numpy

xlwt 中所述

这是对 numpy 行为的检查(Python 2.7.3,numpy 1.6.2)

>>> import numpy
>>> data = [t(123456) for t in (numpy.int32, numpy.int64, numpy.float64)]
>>> [type(d) for d in data]
[<type 'numpy.int32'>, <type 'numpy.int64'>, <type 'numpy.float64'>]
>>> data
[123456, 123456, 123456.0]
>>> check_types = (int, long, float)
>>> for d in data:
...     for c in check_types:
...         print type(d), repr(c), isinstance(d, c)
...
<type 'numpy.int32'> <type 'int'> True
<type 'numpy.int32'> <type 'long'> False
<type 'numpy.int32'> <type 'float'> False
<type 'numpy.int64'> <type 'int'> False
<type 'numpy.int64'> <type 'long'> False
<type 'numpy.int64'> <type 'float'> False
<type 'numpy.float64'> <type 'int'> False
<type 'numpy.float64'> <type 'long'> False
<type 'numpy.float64'> <type 'float'> True
>>>

看起来 numpy 已经完成了使其 int32 和 float64 可以被其他软件识别但不能被 int64 识别的工作。

Proposal numpy.core

最有用的评论

这是正确的——python 'int' 是 32 位或 64 位(取决于您的
建造; 您使用的是 32 位 python),因此 np.int32 或 np.int64
源于它。 np.float32 也不是 'float' 的实例,因为
类似地,Python 'float' 专门以双精度存储。

(真的,即使这是愚蠢的,因为 numpy ints _are不是 'int' 的实例
或“浮动”,但无论如何。)

isinstance(..., int) 是您尝试执行的操作的错误工具。 如果你
想要使用 numpy 类型检测整数,这是最简单的事情
do isinstance(..., np.integer)。

2013 年 1 月 26 日星期六晚上 8:15,Daniel Vianna通知@ github.com 写道:

如 xlwt https://github.com/python-excel/xlwt/issues/15 中所述

这是对 numpy 行为的检查(Python 2.7.3,numpy 1.6.2)

import numpy>>> data = [t(123456) for t in (numpy.int32, numpy.int64, numpy.float64)]>>> [type(d) for d in data][,,]>>> 数据[123456, 123456, 123456.0]>>> check_types = (int, long, float)>>> for d in data:... for c in check_ types:... print type(d), repr(c), isinstance(d, c)...真的错误的错误的错误的错误的错误的错误的错误的真>>>

看起来 numpy 已经完成了使其 int32 和 float64 的工作
可以被其他软件识别,但不能被 int64 识别。


直接回复本邮件或在 Gi tHub https://github.com/numpy/numpy/issues/2951上查看

所有4条评论

这是正确的——python 'int' 是 32 位或 64 位(取决于您的
建造; 您使用的是 32 位 python),因此 np.int32 或 np.int64
源于它。 np.float32 也不是 'float' 的实例,因为
类似地,Python 'float' 专门以双精度存储。

(真的,即使这是愚蠢的,因为 numpy ints _are不是 'int' 的实例
或“浮动”,但无论如何。)

isinstance(..., int) 是您尝试执行的操作的错误工具。 如果你
想要使用 numpy 类型检测整数,这是最简单的事情
do isinstance(..., np.integer)。

2013 年 1 月 26 日星期六晚上 8:15,Daniel Vianna通知@ github.com 写道:

如 xlwt https://github.com/python-excel/xlwt/issues/15 中所述

这是对 numpy 行为的检查(Python 2.7.3,numpy 1.6.2)

import numpy>>> data = [t(123456) for t in (numpy.int32, numpy.int64, numpy.float64)]>>> [type(d) for d in data][,,]>>> 数据[123456, 123456, 123456.0]>>> check_types = (int, long, float)>>> for d in data:... for c in check_ types:... print type(d), repr(c), isinstance(d, c)...真的错误的错误的错误的错误的错误的错误的错误的真>>>

看起来 numpy 已经完成了使其 int32 和 float64 的工作
可以被其他软件识别,但不能被 int64 识别。


直接回复本邮件或在 Gi tHub https://github.com/numpy/numpy/issues/2951上查看

此外,在 Python 3 上,Numpy 的所有整数类型都与本机 int 类型(这是一个可变大小的整数)无关。

我认为纳撒尼尔在他对原始报告的说明中是完全正确的。 Numpy 应该继承/注册numbers.Integral等,这非常适合 Python 2.4 和 2.5 的删除。 如果有人想要广泛认可整数喜欢,他们应该检查numbers.Integral (或者尝试类似的鸭子输入__index__方法)。

从 #4547 和 1.9.0 开始,numpy 使用 number 模块注册数字。 将此作为相关关闭。

此页面是否有帮助?
0 / 5 - 0 等级