[Numpy-discussion] argsort
Robert Kern
robert.kern@gmail....
Tue Jan 15 08:56:10 CST 2013
On Tue, Jan 15, 2013 at 3:44 PM, Charles R Harris
<charlesr.harris@gmail.com> wrote:
> Fancy indexing is a funny creature and not easy to understand in more than
> one dimension. What is happening is that each index is replaced by the
> corresponding row of a and the result is of shape (5,2,2). To do what you
> want to do:
>
> In [20]: a[i, [[0,1]]*5]
> Out[20]:
> array([[ 1, 3],
> [ 4, 6],
> [ 8, 7],
> [11, 9],
> [23, 12]])
>
> I agree that there should be an easier way to do this.
Slightly easier, though no more transparent:
a[i, [0,1]]
http://docs.scipy.org/doc/numpy/user/basics.indexing.html#indexing-multi-dimensional-arrays
--
Robert Kern
More information about the NumPy-Discussion
mailing list