This code should work for your matrix given the kernel size and stride:
kh, kw = 3, 3 # kernel size
dh, dw = 1, 1 # stride

C, M, N = 4, 7, 7
x = torch.randn(M, N, C)

patches = x.unfold(0, kh, dh).unfold(1, kw, dw)
print(patches.shape)
> torch.Size([5, 5, 4, 3, 3])
patches = patches.contiguous().view(*patches.size()[:-2], -1)
patches = torch.pow(torch.pow(patches, 2).sum(3), 0.5)
print(patches.shape)
> torch.Size([5, 5, 4])

You would have to permute the tensor or