[Numpy-discussion] "Advanced indexing" question - subset of data cube as a 2D array.
Wed Oct 29 00:44:06 CDT 2008
Hi numpy group,
I have a problem I know there is an elegant solution to, but I can't
wrap my head around the right way to do the indexing.
I have a 2D array that has been chopped up into 3 dimensions - it was [ time
X detectors ], it is now [ scans X time X detectors ]. During the chopping,
some of the time points and detector points have been removed, so the 3D
array contains only a subset of the data in the 2D array. I'd like to
restore the 3D array back to the shape of the original 2D array b/c it's
being stored in a netCDF file that is not flexible.
In : array2d.shape
Out: (11008, 144)
In : array3d.shape
Out: (23, 337, 107)
In : whscan.shape
In : 23*337
In : temp2d = reshape(array3d,[23*337,107])
In : temp2d2 = zeros([23*337,144])
In : temp2d2[:,f.bolo_indices] = temp2d
In : array2d[whscan,:] = temp2d2
This works, but it feels wrong to me: I think there should be a way to do
this by directly indexing array2d with two numpy arrays....
In the process of asking this question, I might have come up with the answer
(courtesy Stefan at http://mentat.za.net/):
In : bi = (f.bolo_indices[np.newaxis,:]+ones([7751,1])).astype('int')
In : whc = (whscan[:,np.newaxis] + ones([1,107])).astype('int')
In : array2d[whc,bi] = temp2d
I thought this had worked, but the values didn't seem to be going to the
right places when I re-examined them.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion