This can easily be done faster than loops:
a) Use two 7x7 convolution kernels and a stride of (7,7) with no padding to get left mean and right mean.
Then compute your output as y[:, 0] / y[:, 1]
b) Without conv operations via
x_reshaped = x.view(-1, 7, 7)  # possibly need to crop or pad first
output_prelim = x_reshaped[:, :, :3].mean(-1) / x_reshaped[:, :, 4:].mean(-1)
output = output_prelim.view(expected_output_shape)