On the indexing order in (numpy) arrays

Robert Kern robert.kern at gmail.com
Fri Oct 10 01:49:21 CEST 2008

Almar Klein wrote:
>     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 in 
> 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 the 
> pointset class such that points[99,0] selects the *last* dimension of 
> point 99. 
> Or is it?

<shrug> It's occasionally annoying, but in my experience, it's just not a big 
deal. And besides, images aren't always oriented the same way, so there's often 
some more coordinate conversion that needs to be done.

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco

More information about the Python-list mailing list