I’d like to create a 4D mask where the elements are determined by $M[i, j, k, l] = \delta_{i+j, k+l}$. Does anyone have a recommendation for how to do this?
Sure. M[i, j, k, l] = 1 if i + j == k + l and 0 otherwise.