Take the mean of the innermost tensor

I have a tensor like the following:
x = torch.tensor([[[[2, 4, 7],
[6, 5, 4],
[6, 5, 5]],

               [[12, 14, 17],
                [26, 25, 42],
                [62, 52, 52]]]])

Now I want to take the mean of the inner most 3X3 array
So my final array looks like this after taking mean:
[[[4.88],
[33.5]]]
the final size is 1x2x1

Hi,

You can use the torch.mean(t, dim=) function to do that by specifying which dimension you want to compute the mean over.

I do it using
y = x.mean(dim=(2,3), dtype=float)
but it makes the size as (1,2)
but i want (1, 2, 1)

You can use .unsqueeze(-1) to add a new dimension of size 1 on your Tensor.