On the indexing order in (numpy) arrays

Almar Klein almar.klein at gmail.com
Thu Oct 9 23:36:05 CEST 2008

> Basically, we want a[i][j] == a[i,j]. Since there is no literal syntax for
> numpy arrays, we need to be able to convert from a sequence of sequences to
> an array. The indexing needs to correspond between the two.

Thanks for the reply. I guess that explains the *why*...

Adopt the numpy order. There are many functions in numpy which take an axis=
> argument just like this. axis=0 means "y" in the terminology that you are
> using.

Yes, I agree its best to use the numpy order, and I agree one gets
used to it. However, it will always feel a bit unnatural to reverse the
order of dimensions (at least to me it does). And I think it can in
some situations lead to confusion.

I for instance have a class to store sets of points in a nD space. I can
index the points, so using points[99,0] selects the *first* dimension of
the 99th point. I use this class to store locations of interesting points
2D and 3D images. But when programming, it can at times be quite confusing
switching between reversed and "normal" indexing. And sometimes I
might have a method that does stuff with an image and a point set and
I want to indicate an axis. What standard should I use then?

I'm not saying numpy should change the indexing order or something. But
other people must run into the same confusing situation at times. How do
they handle this?  In the example above, I think it'll be weird to change
pointset class such that points[99,0] selects the *last* dimension of point
Or is it?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20081009/8ca2e18b/attachment.html>

More information about the Python-list mailing list