While working on a research problem, I encountered the following rank 4 tensor mask:
M[i,j,k,l] = delta(i+j,k+l)
Where delta(x,y) = 1 iff x==y, else 0 (the kronecker delta)
For example M(2,3,1,4) = 1 since (2+3=1+4) but M(1,3,2,4)= 0 since (1+3 is not 2+4)
Is there a vectorized way to create this using numpy? If I used for loops, I have to go through N^4 iterations which for my current value of N is already too much. Also there's an issue of memory.