[Numpy-discussion] Dealing with roundoff error

Mike Sarahan msarahan at gmail.com
Sat Mar 27 19:38:27 EDT 2010


Hi all,

I have run into some roundoff problems trying to line up some
experimental spectra.  The x coordinates are given in intervals of 0.1
units.  I read the data in from a text file using np.loadtxt().

I think Robert's post here explains why the problem exists:
http://mail.scipy.org/pipermail/numpy-discussion/2007-June/028133.html

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

What is the best way to deal with it?  Multiply the intervals by 10,
then convert them to ints?

Thanks,
Mike



More information about the NumPy-Discussion mailing list