Kaushik Ghose <kaushik_gh...@hms.harvard.edu> writes: > In [2]: pylab.arange(0.5,1.0,.1) > Out[2]: array([ 0.5, 0.6, 0.7, 0.8, 0.9]) <---- OK > > In [3]: pylab.arange(0.5,1.1,.1) > Out[3]: array([ 0.5, 0.6, 0.7, 0.8, 0.9, 1. , 1.1]) <----- Not OK
The "bug" is really in numpy, which is where pylab imports arange from, but even then it's not exactly a bug but a feature of floating-point numerics (.1 is not exactly representable in binary floating-point, so the equality comparison done by arange doesn't make much sense). Use linspace if you know how many values you want: In [4]: linspace(0.5,1.0,num=5,endpoint=False) Out[4]: array([ 0.5, 0.6, 0.7, 0.8, 0.9]) In [5]: linspace(0.5,1.1,num=6,endpoint=False) Out[5]: array([ 0.5, 0.6, 0.7, 0.8, 0.9, 1. ]) -- Jouni K. Seppänen http://www.iki.fi/jks ------------------------------------------------------------------------------ Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise -Strategies to boost innovation and cut costs with open source participation -Receive a $600 discount off the registration fee with the source code: SFAD http://p.sf.net/sfu/XcvMzF8H _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users