Tensor Average based on the output shape

I am new to deep learning. I passed the image through my network and I have received the tensor of shape [1, 1, 48, 48] and I want to take an average and convert it to [1, 48]. How can I do that?

Depending which dimension should be used to calculate the average or mean, you could use:

x = torch.randn(1, 1, 48, 48)
y = x.mean(2) # or .mean(3)
print(y.shape)
y = y.squeeze(1) # or .squeeze(0)
print(y.shape)