Ignore dimension 0 when calculating mean

Is there any way I can calculate the mean of all elements in a 4d tensor except along dim 0 - i.e. the equivalent of tensor.mean(1).mean(1).mean(1)?

if you know the size of the first dimension you can:

tensor.view(size,-1).mean(1)

And if you don’t know it, you could use:

tensor.view(tensor.size(0), -1).mean(1)

:wink:

1 Like