[Numpy-discussion] arange and floating point arguments

Charles R Harris charlesr.harris@gmail....
Fri Sep 14 16:48:00 CDT 2007

On 9/14/07, Timothy Hochberg <tim.hochberg@ieee.org> wrote:
> On 9/14/07, Joris De Ridder <Joris.DeRidder@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.

Exactly. The problem becomes even more dependent on particular circumstance.
For instance, if (.2 + .2 + .1) is used instead  of (.2 + .4).

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.

In the case of arange it should be possible to determine when the result is
potentially ambiguous and issue a warning. For instance, if the argument of
the ceil function is close to its rounded value.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20070914/73a15033/attachment.html 

More information about the Numpy-discussion mailing list