[Numpy-discussion] On responding to dubious ideas (was: Re: Advanced indexing: "fancy" vs. orthogonal)
Alan G Isaac
alan.isaac at gmail.com
Fri Apr 10 12:22:09 EDT 2015
On 4/9/2015 11:26 PM, Alexander Belopolsky wrote:
> > but if I try to do both, I get the diagonal instead
> >
> > >>> a[[1,2],[1,2]]
> > array([22, 33])
> >
> On Thu, Apr 9, 2015 at 8:41 PM, Derek Homeier <derek at astro.physik.uni-goettingen.de <mailto:derek at astro.physik.uni-goettingen.de>> wrote:
> a[1:3,1:3]?
> Can’t be generalised to arbitrary selections of rows,columns, though (e.g. a[1::2,::2] still works…)
On 4/9/2015 11:26 PM, Alexander Belopolsky wrote:
> I am interested in the arbitrary selection of rows and columns given by indices or by boolean selectors.
You mean like this?
import numpy as np
a = np.arange(20).reshape((4,5))
rows = [0,3]
cols = [1,2,4]
print a[rows][:,cols]
Alan Isaac
More information about the NumPy-Discussion
mailing list