Suppose img is a 2 dimensional numpy array. Suppose also that x and y are integer valued 2 dimensional numpy arrays of the same shape as img. Consider:
newImg = img[x, y]
newImg is now a 2 dimensional array of the same shape as img where newImg[i,j] == img[ x[i,j], y[i,j] ] for all i and j.
I want to generalize this procedure to an arbitrary number of dimensions. That is, let img be a d-dimensional numpy array and take x[i], for i in range(0, d), to be an integer valued d-dimensional numpy array of the same shape as img. What I basically want is:
newImg = img[x[0], x[1], ..., x[d-1]]
Which is obviously pseudocode, and not expected to work.
How can I do this with NumPy?