[Numpy-discussion] indexing problem

Robert Kern robert.kern at gmail.com
Tue Aug 18 10:33:24 EDT 2009


2009/8/18 Ernest Adrogué <eadrogue at gmx.net>:
> Hi,
>
> Suppose I have a 3-dimansional array, where one dimension
> is time. I'm not particularly interested in selecting specific
> moments in time, so most of the time I won't be indexing this
> dimension.
>
> Intuitively, one would make time the third dimension, but if
> you do that you have to specifiy the time in every index, which
> is annoying, because then all indices must start with an empty
> slice, e.g.,
>
> a[:,1]
> a[:,:,3]
> a[:,0,1]
>
> etc. On the other hand, the arrays resulting from indexing have
> all elements sorted by time, which is a good thing.
>
> Then, if I change it and make time the first dimension, it's
> handy because I can omit time in indices, BUT then the sub-arrays
> produced by indexing are not sorted by time!

I do not know what you mean by "not sorted by time". You can keep the
sub-arrays sorted however you like regardless of the index used for
time. Can you show us an example of the problem you are seeing?

> Is it possible to change the way numpy traverses the array,
> so that it moves "less" on the first dimension (instead  of the
> default, which is to move less on the last dimension), so that I
> get arrays sorted by time when time is not on the last dimension?

No, but I suspect that the problem you are seeing can be fixed in another way.

-- 
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 NumPy-Discussion mailing list