python - 什么决定了 numpy 中 int 的大小?

标签 python numpy

它似乎不是处理器的“位数”(32 对 64),请参阅 this 上的评论发布,特别是:

Good answer. As I mentioned in my comments above, I'm able to duplicate @suzep136's issue on a Raspberry Pi 3, which uses a 64-bit ARM processor. Any idea why the overflow issue would occur on a 64-bit architecture? The only thing I can think of is that lapack/blas were compiled for a 32-bit core; I think I installed numpy through apt-get. – nrlakin

也不是 C 中 int 的大小,例如在我的机器上:

>>> import numpy, ctypes
>>> 
>>> ctypes.sizeof(ctypes.c_int)
4
>>> numpy.array([1]).dtype
dtype('int64')

那么,它取决于什么?

编辑:还有另一位候选人,谢谢 ev-br:

LAPACK uses 32-bit integers on all architectures – ev-br

编辑:部分答案是 here .谢谢高洋。 我已经复制并制作了它 CW所以你可以添加更好的点,比如 PyPy 中发生的事情或杰通。我也很想知道这个选择是否有更深层次的原因。

最佳答案

感谢Goyo谁太谦虚了,不能把功劳占为己有。查看他们对相关但不同 question 的回答.

numpy 中的默认整数类型是 numpy.int_,一定要注意结尾的下划线。它默认为 C long 1 .

关于python - 什么决定了 numpy 中 int 的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41782767/

相关文章:

Python:字符串无法识别达到一定数量的两位数

python - 将列表作为值的字典与生成值的字典进行比较

python - efrc 给出错误 length-1 数组可以转换为 python

python - 在 Python 中将数组(numpy 数据类型)转换为元组( native 数据类型)

python - 移除/删除 NxM 矩阵每行中的每个最小值?

python - 如何使用 Python Selenium Webdriver 在 Chrome 中加载默认配置文件?

python - 将 pdf 转换为图像时出现类型错误 : TypeError ("object of type ' NoneType' has no len()", )

python - 保存网络摄像头拍摄的快照时显示错误 "incorrect padding"

python:性能图像切片numpy

Python Dataframe 在将多个列值与一个值进行比较后删除行