Why arange has no stop-point opt-in?
Dear all, I'm a bit puzzled that there seems just no way to cleanly code an interval with evenly spaced numbers that includes the stop point given? linspace offers to include the stop point, but arange does not? Am I missing something? (I am aware, that I could do arange(9,15.0001,0.1) but that's what I want to avoid!) Best regards and Happy New Year! Michael
2010/12/30 K.-Michael Aye
I'm a bit puzzled that there seems just no way to cleanly code an interval with evenly spaced numbers that includes the stop point given? linspace offers to include the stop point, but arange does not? Am I missing something? (I am aware, that I could do arange(9,15.0001,0.1) but that's what I want to avoid!)
Use numpy.linspace(9, 15, 7 * 10 + 1). FYI, there is also numpy.logspace(). Friedrich
2010/12/30 Friedrich Romstedt
2010/12/30 K.-Michael Aye
: I'm a bit puzzled that there seems just no way to cleanly code an interval with evenly spaced numbers that includes the stop point given? linspace offers to include the stop point, but arange does not? Am I missing something? (I am aware, that I could do arange(9,15.0001,0.1) but that's what I want to avoid!)
Use numpy.linspace(9, 15, 7 * 10 + 1). FYI, there is also numpy.logspace().
Oh sorry, I overlooked that you're aware of the linspace functionality. Sorry. I think opting in or opting out the end point in arange() is at even rate, because it's in both cases the same unreliable (about including or not including the end point). Because it might pick a) if opting in a point just 1e-14 above so not opting in as desired and b) vice verse if opting out, it might pick a point just 1e-14 below. But I believe someone more educated about fp issues will give a more authoritative reply. Friedrich
On Thu, Dec 30, 2010 at 9:08 AM, Friedrich Romstedt
2010/12/30 Friedrich Romstedt
: 2010/12/30 K.-Michael Aye
: I'm a bit puzzled that there seems just no way to cleanly code an interval with evenly spaced numbers that includes the stop point given? linspace offers to include the stop point, but arange does not? Am I missing something? (I am aware, that I could do arange(9,15.0001,0.1) but that's what I want to avoid!)
Use numpy.linspace(9, 15, 7 * 10 + 1). FYI, there is also numpy.logspace().
Oh sorry, I overlooked that you're aware of the linspace functionality. Sorry.
I think opting in or opting out the end point in arange() is at even rate, because it's in both cases the same unreliable (about including or not including the end point). Because it might pick a) if opting in a point just 1e-14 above so not opting in as desired and b) vice verse if opting out, it might pick a point just 1e-14 below. But I believe someone more educated about fp issues will give a more authoritative reply.
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) Josef
Friedrich _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
On 2010-12-30 16:43:12 +0200, josef.pktd@gmail.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 case. 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? Michael
Josef
Friedrich _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
2010/12/30 K.-Michael Aye
On 2010-12-30 16:43:12 +0200, josef.pktd@gmail.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 case. 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 Matthieu -- Information System Engineer, Ph.D. Blog: http://matt.eifelle.com LinkedIn: http://www.linkedin.com/in/matthieubrucher
participants (4)
-
Friedrich Romstedt
-
josef.pktd@gmail.com
-
K.-Michael Aye
-
Matthieu Brucher