I'm trying to vectorize the following code -
for i in range(imL.shape[0]):
for j in range(imL.shape[1]):
if j - disp[i][j] >= 0:
imR[i, j - disp[i][j], :] = imL[i, j, :]
Essentially, I want to do this -
A[i, j - B[i, j], k] = C[i, j, k] for all (i, j, k)
I looked into boolean indexing and came up with this -
tmp = np.arange(imR.shape[1])
tmp = np.repeat(tmp[np.newaxis, :], imR.shape[0], axis=0)
tmp = np.repeat(tmp[:, :, np.newaxis], imR.shape[2], axis=2)
imR[(tmp - disp) >= 0] = imL
However, this throws up the error -
TypeError: NumPy boolean array indexing assignment requires a 0 or 1-dimensional input, input has 3 dimensions
I believe integer indexing is the solution, however, I am unable to come up with anything. Is there a way to vectorize this efficiently?
NOTE: imL and imR are N x M x 3 ndarrays. disp is an N x M ndarray.