python - 什么决定了 numpy 数组的数据类型

标签 python arrays numpy

我正在使用 Python(Windows 64 位)。我编写了以下脚本:

y = np.array[(4,5,6)]
z = np.array([y, y**2])
z.dtype

当我运行上面的代码时,它返回类型“int32”,但是完全相同的代码在 Christopher Brooks Coursera 类(class) Introduction to Data Science in Python 中给出了“int64”值.

为什么会这样?

最佳答案

NumPy defaults to converting Python ints to numpy.int_ ,对应于 C long 的数据类型。在 Windows 上,C long 即使在 64 位机器上也是 32 位。在 Linux 上,C long 是 64 位,因此您会得到 np.int64

关于python - 什么决定了 numpy 数组的数据类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46938334/

相关文章:

python - 为什么我会得到这个 AttributeError?

python - 在不损失精度的情况下转换 np.datetime64 的时区

c - C中两个数组相加

python - 用于逆矩阵和稀疏矩阵乘积的高效 numpy/lapack 例程?

python - 'numpy.float64' 对象不可迭代 - 基于内容的过滤模型

python - 使 QGraphicsItem 只能在一个图形 View 中选择

python - pyspark RDD 将一行扩展为多行

Ruby 将数组分成 X 组

javascript - 使用循环将多个数组组合成一个对象

python - 值错误: Domain error in arguments scipy rv_continuous