>>> a = torch.randn(4, 4)
>>> torch.mean(a, 1)
-0.5172
-0.2325
0.4547
-0.6532
[torch.FloatTensor of size 4x1]
>>> torch.mean(a, 1, True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: torch.mean received an invalid combination of arguments - got (torch.FloatTensor, int, bool), but expected one of:
* (torch.FloatTensor source)
* (torch.FloatTensor source, int dim)

How can I solve this error ?
Also, how can I compute the mean of a matrix ? For instance, I have a b x c x h x w tensor, and I would like to compute the mean of each feature map, so that I got a b x c x 1 x 1 mean tensor. Just like np.mean(a, dim=(2,3)) does.

This is a relatively recent change, you may want to upgrade your pytorch version. Also I am not even sure that it is in the binary releases yet and may only be available with the source install.

For your problem, doesn’t the regular torch.mean does what you want?

Thanks for this quick response. You’re right, it’s not in the binary release. I will try compile with the source. Also, it doesn’t do what I want. For instance, I have a 1x3x4x4 tensor, what I would like to do is to compute the mean of the 3 channels so that I get a tensor of size 1x3x1x1, while torch.mean will only calculate mean of a single dimension not cross two dimensions.
>>> import torch
>>> a = torch.randn(1, 3, 4, 4)
>>> torch.mean(a)
-0.1468020509540414
>>> torch.mean(a,dim=1)