[Numpy-discussion] arange and floating point arguments

Anne Archibald peridot.faceted@gmail....
Fri Sep 14 11:01:34 CDT 2007


On 14/09/2007, Robert Kern <robert.kern@gmail.com> wrote:
> Ed Schofield wrote:
> > Using arange in this way is a fundamentally unreliable thing to do,
> > but is there anything we want to do about this?
>
> Tell people to use linspace(). Yes, it does a slightly different thing; that's
> why it works. Most uses of floating point arange() can be cast using linspace()
> more reliably.

I would like to point out in particular that numpy's linspace can
leave out the last point (something I often want to do):

Definition:     linspace(start, stop, num=50, endpoint=True, retstep=False)
Docstring:
    Return evenly spaced numbers.

    Return num evenly spaced samples from start to stop.  If
    endpoint is True, the last sample is stop. If retstep is
    True then return the step value used.

This is one of those cases where "from pylab import *" is going to
bite you, though, because its linspace doesn't. You can always fake it
with linspace(a,b,N+1)[:-1].

Anne


More information about the Numpy-discussion mailing list