[Numpy-discussion] taking a 2D uneven surface slice

Bryan Woods bwoods@aer....
Tue Apr 16 15:21:52 CDT 2013


I'm trying to do something that at first glance I think should be simple 
but I can't quite figure out how to do it. The problem is as follows:

I have a 3D grid Values[Nx, Ny, Nz]

I want to slice Values at a 2D surface in the Z dimension specified by 
Z_index[Nx, Ny] and return a 2D  slice[Nx, Ny].

It is not as simple as Values[:,:,Z_index].

I tried this:
 >>> values.shape
(4, 5, 6)
 >>> coords.shape
(4, 5)
 >>> slice = values[:,:,coords]
 >>> slice.shape
(4, 5, 4, 5)
 >>> slice = np.take(values, coords, axis=2)
 >>> slice.shape
(4, 5, 4, 5)
 >>>

Obviously I could create an empty 2D slice and then fill it by using 
np.ndenumerate to fill it point by point by selecting values[i, j, 
Z_index[i, j]]. This just seems too inefficient and not very pythonic.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bwoods.vcf
Type: text/x-vcard
Size: 341 bytes
Desc: not available
Url : http://mail.scipy.org/pipermail/numpy-discussion/attachments/20130416/09962ca6/attachment.vcf 


More information about the NumPy-Discussion mailing list