I’m not sure about the exact code but you can use range and expand to have matrices like A[i, j] = i, forall j: range(1000).unsqueeze(1).expand(1000, 2000). And the same for the other one with unsqueeze(0).
Then you can substract them element-wise and take the absolute value of the result.