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

Keith Goodman kwgoodman at gmail.com
Mon Jul 3 20:53:33 CDT 2006

On 7/2/06, Webb Sprague <webb.sprague at gmail.com> wrote:

> 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
> programming.

Aha! Guido himself prefers starting the index at one. Here's a code
snippet from a fun article he wrote about optimizing python code:

    import time
    def timing(f, n, a):
        print f.__name__,
        r = range(n)
        t1 = time.clock()
        for i in r:
            f(a); f(a); f(a); f(a); f(a); f(a); f(a); f(a); f(a); f(a)
        t2 = time.clock()
        print round(t2-t1, 3)


Notice he chose t1 and t2 instead of t0 and t1.


More information about the Numpy-discussion mailing list