Get the mean of a 2D tensor for each column

Hello, I want to know what is the most simple way to get the mean of the matrix along each column, namely my tensor only has two dimensions with shape (m X n).

For example, if I have a tensor object

T = torch.FloatTensor([[2.6, 5], [1.7, 6], [3.2, 7], [2.1, 8]])

I want some function that could return a tensor object as following

([2.4, 6.5])

I know I could do with for loop, but I wonder if there is a PyTorch built-in method that could do this for me, or is there some more elegant way for this purpose.

mean = torch.zeros(T.size(1))
for i in range(T.size(1)):
  mean[i] = torch.mean(T[:, i])

Thanks for any help.

Anyway, I didn’t understand the argument “dim” correctly, with “dim” argument “torch.mean(T, dim=i)” do everything for me, but for getting the mean of each column, i=0 is the correct dimension.