NumPy 的精度错误



有人可以解释一下:

>>> numpy.array([22.0], dtype=numpy.float64) / (2 ** 11)
array([0.01074219])
>>> 22.0 / (2 ** 11)
0.0107421875
>>> 

Numpy 似乎生成了一个错误的结果,可能是某种精度错误。

我该如何解决这个问题?

>>> numpy.set_printoptions(precision=15)
>>> numpy.array([22.0], dtype=numpy.float64) / (2 ** 11)
array([0.0107421875])

修复此问题

最新更新