Different behavior with torch.mean(data, 0) and torch.mean(data) for vector
I was surprised to find different behavior with torch.mean(data, 0) and torch.mean(data), where "data" — is 1D-tensor (vector, not a matrix or something else):

from torchvision import datasets
import torch

path = './MNIST_data'

data = datasets.MNIST(path, train=True, download=True).train_data.view(-1).float()

print(torch.mean(data))
print(torch.mean(data, 0))


Results after execution:

tensor(33.3184)
tensor(33.4961)


Could anyone suppose what is going on? I assumed that the results should be the same.

An Example should help you clear your doubt.

Lets say we have data = torch.Tensor([[1,2,3,4],[1,2,3,4]])

Now When you perform torch.mean(data),It will sum all the elements in the data tensor and divide that by the number of elements in that tensor,Giving you a result of 2.5

As for your operation of torch.mean(data, 0) This will perform mean along the horizontal direction,which means it will take the first element of row one which is 1 and take the first element of row 2 which is 2,sum them up and divide by 2.It helps to visualize the data array this way 

[1, 2, 3, 4]
[1, 2, 3, 4]


The final result will be tensor of [1, 2, 3, 4] if you know how we ended up getting this tensor, You've understood the difference.

Hope that clears it, Let me know if you have questions 
