[Numpy-discussion] indexing question
Ernest Adrogué
eadrogue@gmx....
Sun Nov 21 13:15:00 CST 2010
Hi,
Suppose an array of shape (N,2,2), that is N arrays of
shape (2,2). I want to select an element (x,y) from each one
of the subarrays, so I get a 1-dimensional array of length
N. For instance:
In [228]: t=np.arange(8).reshape(2,2,2)
In [229]: t
Out[229]:
array([[[0, 1],
[2, 3]],
[[4, 5],
[6, 7]]])
In [230]: x=[0,1]
In [231]: y=[1,1]
In [232]: t[[0,1],x,y]
Out[232]: array([1, 7])
This way, I get the elements (0,1) and (1,1) which is what
I wanted. The question is: is it possible to omit the [0,1]
in the index?
Thanks in advance.
--
Ernest
More information about the NumPy-Discussion
mailing list