[Numpy-discussion] arange and floating point arguments

Timothy Hochberg tim.hochberg at ieee.org
Fri Sep 14 16:59:48 EDT 2007


On 9/14/07, Joris De Ridder <Joris.DeRidder at ster.kuleuven.be> wrote:
>
>
>
> > the question is how to reduce user astonishment.
>
> IMHO this is exactly the point. There seems to be two questions here:
> 1) do we want to reduce user astonishment, and 2) if yes, how could
> we do this? Not everyone seems to be convinced of the first question,
> replying that in many cases linspace() could well replace arange().
> In many cases, yes, but not all. For some cases arange() has its
> legitimate use, even for floating point, and in these cases you may
> get bitten by the inexact number representation. If Matlab seems to
> be able to avoid surprises, why not numpy?


Perhaps because it's a bad idea? This case may be different, but in general
in cases where you try to sweep the surprising nature of floating point
under the rug, you are never entirely successful. The end result is that,
although surprises crop up with less regularity, they are much, much harder
to diagnose and understand when they do crop up.

If arange can be "fixed" in a way that's easy to understand, then great.
However, if the algorithm for deciding the points is anything but dirt
simple, leave it alone. Or, perhaps, deprecate floating point values as
arguments. I'm not very convinced by the arguments advanced thus far that
arange with floating point has legitimate uses. I've certainly used it this
way myself, but I believe that all of my uses could easily be replaced with
either linspace or arange with integer arguments.  I suspect that cases
where the exact properties of arange are required are far between and it's
easy enough to simulate the current behaviour if needed. An advantage to
that is that the potential pitfalls become obvious when you roll your own
version.



-- 
.  __
.   |-\
.
.  tim.hochberg at ieee.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20070914/62d9abd2/attachment.html>


More information about the NumPy-Discussion mailing list