Let's say that we have two numpy ndarrays with shapes:
video.shape = (v, h, w, 3)
and
image.shape = (h, w, 3)
We also have an array with shape img.shape = (h,w) that is integer and tells me which "frame" v to pick for each position h,w. To do this, one can use the loop:
for j in range(w):
for i in range(h):
image[i, j, :] = video[img[i, j], i, j, :]
However, this is very slow. Is it possible to do it without loops? Maybe reshaping the 2D coordinates into one and then reshaping it back?