We need more code and context for a better explanation but what is happening in this line:
x is a tensor with dimesnion = 4 (if it’s an image we have batchsize, channels, widht,height)
(x[:, 0, :, :-1] - x[:, 0, :, 1:])**2

this subtracts x[all, 0, all, from 0 to the second last index) with x[all, 0, all from 1 to the last index] and then uses the power of two.
The same is happening here
x[:, 1, :, :-1] - x[:, 1, :, 1:])**2

But now we use in the second dimension the second index
All of that is now used with the power of 0.5 (this is the square root) and then all calculated values are summed.
In the end you have only one value