Le 07/02/2011 13:37, josef.p...@gmail.com a écrit :
> n0, n1 = k.shape
> ind0 = np.arange(n0)[:,None]
> ind1 = np.arange(n1)
> q0 = C1[ind0,ind1, k[ind0,ind1]]
>
> or better
> q0 = C1[ind0,ind1, k]
Great!!!
Thanks a lot.
Cheers,
--
Fred
___
NumPy-Dis
On Mon, Feb 7, 2011 at 7:21 AM, Fred wrote:
> Hi all,
>
> Let's say C1 is a 3D array,
> and q0 and k are 2D array.
>
> dim C1 = nx*ny*nz
>
> dim q0 = nx*ny = dim k
>
> I have to do the following:
>
> q0[0, 0] = C1[0, 0, k[0, 0]]
> q0[1, 1] = C1[1, 1, k[1, 1]]
> ...
> q0[i, j] = C1[i, j, k[i, j]]
>
Hi all,
Let's say C1 is a 3D array,
and q0 and k are 2D array.
dim C1 = nx*ny*nz
dim q0 = nx*ny = dim k
I have to do the following:
q0[0, 0] = C1[0, 0, k[0, 0]]
q0[1, 1] = C1[1, 1, k[1, 1]]
...
q0[i, j] = C1[i, j, k[i, j]]
...
I tried
q0 = C1[:, :, k]
but this obviously does not work.
How