[Numpy-discussion] indexing question

John Salvatier jsalvati at u.washington.edu
Mon Nov 22 14:20:35 EST 2010


I didn't realize the x's and y's were varying the first time around.
There's probably a way to omit it, but I think the conceptually
simplest way is probably what you had to begin with. Build an index by
saying i = numpy.arange(0, t.shape[0])

then you can do t[i, x,y]

On Mon, Nov 22, 2010 at 11:08 AM, Christopher Barker
<Chris.Barker at noaa.gov> wrote:
> On 11/21/10 11:37 AM, Ernest Adrogué wrote:
>>> so you want
>>>
>>> t[:,x,y]
>>
>> I tried that, but it's not the same:
>>
>> In [307]: t[[0,1],x,y]
>> Out[307]: array([1, 7])
>>
>> In [308]: t[:,x,y]
>> Out[308]:
>> array([[1, 3],
>>         [5, 7]])
>
> what is your t? Here's my example, which I think matches what you asked for:
>
> In [1]: import numpy as np
>
> In [2]: a = np.arange(12)
>
> In [3]: a.shape = (3,2,2)
>
> In [4]: a
> Out[4]:
> array([[[ 0,  1],
>         [ 2,  3]],
>
>        [[ 4,  5],
>         [ 6,  7]],
>
>        [[ 8,  9],
>         [10, 11]]])
>
> In [5]: a[:,1,0]
> Out[5]: array([ 2,  6, 10])
>
>
>
>
> --
> Christopher Barker, Ph.D.
> Oceanographer
>
> Emergency Response Division
> NOAA/NOS/OR&R            (206) 526-6959   voice
> 7600 Sand Point Way NE   (206) 526-6329   fax
> Seattle, WA  98115       (206) 526-6317   main reception
>
> Chris.Barker at noaa.gov
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>



More information about the NumPy-Discussion mailing list