[Numpy-discussion] Multidimensional Indexing

Nikolay Mayorov n59_ru at hotmail.com
Tue Apr 7 09:02:24 EDT 2015


I think the rationale is to allow selection of whole rows / columns. If you want to choose a single element from each row/column, then, yes, you have to pass np.arange(...). There is also np.choose function, but not recommended to use for such cases as far as I understand. I'm not an expert, though.
Nikolay.

> From: misnomer at gmail.com
> Date: Tue, 7 Apr 2015 00:49:34 +0100
> To: numpy-discussion at scipy.org
> Subject: [Numpy-discussion] Multidimensional Indexing
> 
> With the indexing example from the documentation:
> 
> y = np.arange(35).reshape(5,7)
> 
> Why does selecting an item from explicitly every row work as I’d expect:
> >>> y[np.array([0,1,2,3,4]),np.array([0,0,0,0,0])]
> array([ 0,  7, 14, 21, 28])
> 
> But doing so from a full slice (which, I would naively expect to mean “Every Row”) has some…other… behaviour:
> 
> >>> y[:,np.array([0,0,0,0,0])]
> array([[ 0,  0,  0,  0,  0],
>        [ 7,  7,  7,  7,  7],
>        [14, 14, 14, 14, 14],
>        [21, 21, 21, 21, 21],
>        [28, 28, 28, 28, 28]])
> 
> What is going on in this example, and how do I get what I expect? By explicitly passing in an extra array with value===index? What is the rationale for this difference in behaviour?
> 
> Thanks,
> 
> Nick
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20150407/58dee0b7/attachment.html>


More information about the NumPy-Discussion mailing list