How can I take elements from a NumPy array given multiple index arrays with broadcasting? Or: how can I simplify/vectorize this loop:
elems = np.random.rand(3, 10, 7) # shape N x I x M
ind = np.array([[1, 2], [3, 4], [0, 9]]) # shape N x J
res = np.stack([elems[i, ind[i]] for i in range(len(elems))]) # shape N x J x M