[Numpy-discussion] arange(start, stop, step) and floating point (Ticket #8)

Sasha ndarray at mac.com
Wed Feb 8 14:51:10 CST 2006


On 2/8/06, Robert Kern <robert.kern at gmail.com> wrote:
>  ...
> arange() does allow for fractional steps unlinke range(). You may fix the
> docstring if you like. However, I don't think it is possible to ensure that
> invariant in the face of floating point. That's why we have linspace().

There is certainly a way to ensure that arange(..., stop, ...)[-1] <
stop in the face of floating point -- just repeat start += step with
start in a volatile double variable until it exceeds stop to get the
length of the result.   There might be an O(1) solution as well, but
it may require some assumptions about the floating point unit.

In any case, I can do one of the following depending on a vote:

1 (default). Document length=ceil((stop - start)/step) in the arange docstring
2. Change arange to be a fast equivalent of array(range(start, stop,
step), dtype).
3. Change arange to ensure that arange(..., stop, ...)[-1] < stop.

Please vote on 1-3.

-- sasha




More information about the Numpy-discussion mailing list