[Numpy-discussion] Dealing with roundoff error

Pauli Virtanen pav@iki...
Sun Mar 28 01:25:22 CDT 2010


Mike Sarahan wrote:
> However, even linspace shows roundoff error:
>
> a=np.linspace(0.0,10.0,endpoint=False)
> b=np.linspace(0.1,10.1,endpoint=False)
> np.sum(a[1:]==b[:-1])  # Gives me 72, no 100

Are you sure equally spaced floating point numbers having this property even exist? 0.1 does not have a terminating representation in base-2:

0.1_10 = 0.0001100110011001100110011.._2

-- 
Pauli Virtanen


More information about the NumPy-Discussion mailing list