[Numpy-discussion] Does zero based indexing drive anyone else crazy?

Webb Sprague webb.sprague at gmail.com
Sun Jul 2 18:36:14 CDT 2006

Hi Numpeans,

I have been working on a web-based scientific application for about a
year, most of which had been written in either Matlab or SPLUS/R.  My
task has been to make it "driveable" through an online interface (if
anyone cares about mortality forecasting, drop me an email and we can
chat about it offline).  I chose Python/Numpy for the language because
Python and Numpy are both so full featured and easy to work with
(except for one little thing...), and neither Matlab nor R could
gracefully deal with CGI programming (misguided propaganda

However....  I have spent a huge amount of my time fixing and bending
my head around off-by-one errors caused by trying to index matrices
using 0 to n-1.  The problem is two-fold (threefold if you count my
limited IQ...):  one, all the formulas in the literature use 1 to n
indexing except for some small exceptions.  Second and more important,
it is far more natural to program if the indices are aligned with the
counts of the elements (I think there is a way to express that idea in
modern algebra but I can't recall it).  This lets you say "how many
are there?  Three--ok, grab the third one and do whatever to it" etc.
Or "how many?  zero--ok don't do anything".  With zero-based indexing,
you are always translating between counts and indices, but such
translation is never a problem in one-based indexing.

Given the long history of python and its ancestry in C (for which zero
based indexing made lots of sense since it dovetailed with thinking in
memory offsets in systems programming), there is probably nothing to
be done now.  I guess I just want to vent, but also to ask if anyone
has found any way to deal with this issue in their own scientific

Or maybe I am the only with this problem, and if I were a real
programmer would translate into zero indexing without even

Anyway, thanks for listening...

More information about the Numpy-discussion mailing list