Calculating Variance in Pytorch on Spatial axis
I am trying to calculate variance in Pytorch but unable to do on multiple axis.

I have similar thing done in Tensorflow but unable to do it on Pytorch as torch.var function takes int as dimension instead of axes.
Below code is channel last code, I expect axes=[2,3] 

Lambda(lambda x: tf.nn.moments(x, axes=[1, 2]))


For example, if input_dims = (5, 10, 25, 25) then output_dims should be (5,10, 1, 1). 

One thing you can do is to use tensor.view() to flatten all the dimensions that you want to calculate the variance for into one dimension before you apply the var() method:

torch.var(x.view(x.shape[0], x.shape[1], 1, -1,), dim=3, keepdim=True)

I used keepdim=True to keep the dimension that we calculate the variance for to get the desired output shape.
