我正在使用 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/