[Numpy-discussion] step paramter for linspace
Fri Mar 1 08:14:35 CST 2013
On Fri, 2013-03-01 at 13:34 +0000, Nathaniel Smith wrote:
> > My usual hack to deal with the numerical bounds issue is to
> > half the step.
> Right. Which is exactly the sort of annoying, content-free code that a
> library is supposed to handle for you, so you can save mental energy
> for more important things :-).
I agree with the sentiment (I sometimes wish a library could read my
mind ;) but putting this sort of logic into the library seems dangerous
The point is that the coder _should_ understand the subtleties of
floating point numbers. IMO arange _should_ be well specified and
actually operate on the half open interval; continuing to add a step
until >= the limit is clear and always unambiguous.
Unfortunately, the docs tell me that this isn't the case:
"For floating point arguments, the length of the result is
``ceil((stop - start)/step)``. Because of floating point overflow,
this rule may result in the last element of `out` being greater
In my jet-lag addled state, i can't see when this out[-1] > stop case
will occur, but I can take it as true. It does seem to be problematic
As soon as you allow freeform setting of the stop value, problems are
going to be encountered. Who's to say that the stop - delta is actually
_meant_ to be below the limit, or is meant to be the limit? Certainly
not the library!
It just seems to me that this will lead to lots of bad code in which the
writer has glossed over an ambiguous case.
More information about the NumPy-Discussion