pkb = np.zeros((3,3)) pkb[1,1] = 1 pkb[0,1] = -1 dkb = np.zeros((3,3)) dkb[1,1] = 1 dkb[0,0] = -1/2 diffs = np.zeros(shape=(*a.shape, 8)) for rot in range(4): pk = np.rot90(pkb, k=rot) dk = np.rot90(dkb, k=rot) pc = correlate(a, pk, mode='constant', cval=0.0) dc = correlate(a, dk, mode='constant', cval=0.0) diffs[:, :, rot] = pc diffs[:, :, rot+4] = dc