[Numpy-discussion] Why arange has no stop-point opt-in?
Thu Dec 30 09:12:03 CST 2010
2010/12/30 K.-Michael Aye <firstname.lastname@example.org>:
> On 2010-12-30 16:43:12 +0200, email@example.com said:
>> Since linspace exists, I don't see much point in adding the stop point
>> in arange. I use arange mainly for integers as numpy equivalent of
>> python's range. And I often need arange(n+1) which is less writing
>> than arange(n, include_end_point=True)
> I agree with the point of writing gets more in some cases.
> But arange(a, n+1, 0.1) would of course fail in this case.
> And the big difference is, that I need to calculate first how many
> steps it is for linspace to achieve what I believe is a frequent user
> As we already have the 'convenience' of both linspace and arange, which
> in principle could be done by one function alone if we'd precalculate
> all required information ourselves, why not go the full way, and take
> all overhead away from the user?
I think arange() should really be seen as just the numpy version of range().
The issue with including the stop point is that it well may be the
case when you do arange(0, 1, 0.1). It's just a matter of loat
precision. In this case, I think the safest course of action is to let
the user decide how it can handle this.
If the step can be expressed as a rational fraction, then using arange
with floats and a step of one, it may be the simplest way to achieve
what you want.
i.e. : np.arange(90., 150.+1) / 10
Information System Engineer, Ph.D.
More information about the NumPy-Discussion