I have a numpy array:
theta = np.random.normal(size = [1000, 30, 80, 10])
I have an index array:
delta = np.empty([1000, 30, 50], dtype = int)
delta[0,:] = np.arange(50) # stand-in for integer indexing
I want to index the theta array using the delta array.  That is, I want something like
theta[0,delta[0]]
Where the entry associated with delta[0,20,11] will be theta[0,20,delta[0,20,11]].  E.g., I want to back out the row index.  How would I go about this?
Optimally, the output of this would be either have shape [30,50,10] or [30*50, 10].
I'm now using: I'm now using:
theta_unravel = np.repeat(np.arange(30), 50)
theta[0,theta_unravel,delta[0].ravel()]
which appears to work (delivers [30 * 50, 10] result), but I don't know if this is an ideal solution.  Rather, I don't know if this is the fastest solution.
deltadoesn't make sense. It has shape (3,). Did you mean a (1000,30,50) shaped indexing array? WIth valid values for the last dimension oftheta?deltaare an integer index of the third axis oftheta. The second axis ofthetashould be inferred by the row on the second axis ofdelta. So, by relationships,delta.shape[0] == theta.shape[0],delta.shape[1] == theta.shape[1], anddelta.max() < theta.shape[2].np.empty_like(theta), which creates an empty array with the same shape and data type astheta