我原本希望numpy的arange(start,end)
产生范围为[start,end]的值。下面的例子说明了这并不总是正确的(最终值大于end
):
import numpy as np
start=2e9
end=start+321
step=0.066833171999
x=np.arange(start,end,step=step)
print x[-1]>end # Prints "True"
print x[-1]-end # Prints 0.00013661384582519531
这个错误似乎太大了,不可能是由机器精度引起的(但也许我想错了)。发生什么事?在
PS:我使用的是Numpy 1.10.1版
来自
arange
文档:数组长度的
step
倍大于321。linspace
对端点更加小心。在相关问题 更多 >
编程相关推荐