I'd like to vectorise the difference of two M x N arrays across different slices in NumPy. Something like this:
dA = A[1:,:] - A[:-1,:]
dB = B[:,1:] - B[:,:-1]
C = dA * dB
But since dA is (M-1) x N and dB is M x (N-1), it's not a valid operation.
In other words, is there a way to vectorise this loop in NumPy?
for i in range(M-1):
for j in range(N-1):
C[i,j] = (A[i+1,j] - A[i,j])*(B[i,j+1] - B[i,j])