[Numpy-discussion] number ranges (was Re: Matlab page on scipy wiki)

Bill Baxter wbaxter at gmail.com
Mon Feb 13 18:55:01 CST 2006

On 2/11/06, Gary Ruben <gruben at bigpond.net.au> wrote:
> Sasha wrote:
> > On 2/10/06, Gary Ruben <gruben at bigpond.net.au> wrote:
> >> ...  I must say that Travis's
> >> example numpy.r_[1,0,1:5,0,1] highlights my pet hate with python - that
> >> the upper limit on an integer range is non-inclusive.
> >
> > In this case you must hate that an integer range starts at 0 (I don't
> > think you would want len(range(10)) to be 11).

First, I think the range() function in python is ugly to begin with.  Why
can't python just support range notation directly like 'for a in 0:10'.  Or
with 0..10 or 0...10 syntax.  That seems to make a lot more sense to me than
having to call a named function.   Anyway, that's a python pet peeve, and
python's probably not going to change something so fundamental...

Second, sometimes zero-based, non-inclusive ranges are handy, and sometimes
one-based inclusive ranges are handy.  For array indexing, I personally like
zero based.  But sometimes I just want a list of N numbers like a human
would write it, from 1 to N, and in those cases it seems really odd for N+1
to show up.

This is a place where numpy could do something.  I think it would be nice if
numpy had something like an 'irange' (inclusive range) function to
complement the 'arange' function.  They would act pretty much the same,
except irange(5) would return [1,2,3,4,5], and irange(1,5) would return

Anyway, I think I'm going to put a little irange function in my setup.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20060213/007bd32c/attachment.html 

More information about the Numpy-discussion mailing list