
April 16, 2013
2:21 p.m.
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.