[Numpy-discussion] Dealing with roundoff error

Pauli Virtanen pav at iki.fi
Sun Mar 28 02:25:22 EDT 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