[Numpy-discussion] indexing question
Christopher Barker
Chris.Barker at noaa.gov
Mon Nov 22 14:08:20 EST 2010
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
More information about the NumPy-Discussion
mailing list