[Numpy-discussion] 2D (or n-d) fancy indexing?

Zachary Pincus zachary.pincus@yale....
Wed Oct 8 20:44:15 CDT 2008

> You need to give an array for each axis. Each of these arrays will be
> broadcast against each other to form three arrays of the desired shape
> of composite. This is discussed in the manual here:
>  http://mentat.za.net/numpy/refguide/indexing.xhtml#indexing-multi-dimensional-arrays
> Conceptually, you need arrays A, B, and C such that
>  composite[x,y] == images[A[x,y], B[x,y], C[x,y]]
>  for all x,y

Aha -- thanks especially for the clear illustration of what B and C  
need to be. That really helps.

> In [32]: composite = images[map, arange(Nx)[:,newaxis], arange(Ny)]
> When arange(Nx)[:,newaxis] and arange(Ny) get broadcasted with map,
> you get (480,640) arrays like you would get with mgrid[0:Nx,0:Ny].

That's very handy indeed. Thanks for your help!


More information about the Numpy-discussion mailing list