[Numpy-discussion] numpy.arange() error?
Thu Feb 9 19:22:23 CST 2012
On Thu, Feb 9, 2012 at 3:40 PM, Benjamin Root <email@example.com> wrote:
> On Thursday, February 9, 2012, Sturla Molden <firstname.lastname@example.org> wrote:
> > Den 9. feb. 2012 kl. 22:44 skrev eat <email@example.com>:
> > Maybe this issue is raised also earlier, but wouldn't it be more
> consistent to let arange operate only with integers (like Python's range)
> and let linspace handle the floats as well?
> > Perhaps. Another possibility would be to let arange take decimal
> arguments, possibly entered as text strings.
> > Sturla
> Personally, I treat arange() to mean, "give me a sequence of values from x
> to y, exclusive, with a specific step size". Nowhere in that statement
> does it guarantee a particular number of elements. Whereas linspace()
> means, "give me a sequence of evenly spaced numbers from x to y, optionally
> inclusive, such that there are exactly N elements". They complement each
> other well.
I agree -- both functions are useful and I think about them the same way.
The unfortunate part is that tiny precision errors in y can make arange
appear to be "sometimes-exclusive" rather than always exclusive. I've
always imagined there to be a sort of duality between the two functions,
where arange(low, high, step) == linspace(low, high-step,
round((high-low)/step)) in cases where (high - low)/step is integral, but
it turns out this is not the case.
> There are times when I intentionally will specify a range where the step
> size will not nicely fit. i.e.- np.arange(1, 7, 3.5). I wouldn't want this
> to change.
Nor would I. What I meant to express earlier is that I like how Matlab
addresses this particular class of floating point precision errors, not
that I think arange output should somehow include both endpoints.
> My vote is that if users want matlab-colon-like behavior, we could make a
> new function - maybe erange() for "exact range"?
> Ben Root
That could work; it would completely replace arange for me in every
circumstance I can think of, but I understand we can't just go changing the
behavior of core functions.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion