1 使用 torch 对矩阵按行,案列求平均
调用的函数是 torch.mean();
默认情况下是所矩阵所有元素求平均:
>>> a = torch.Tensor([1,2,3,4,5,6]).view(2,3)
>>> x = torch.mean(a)
>>> x
tensor(3.5000)
指定维度,按行求平均(dim = 0), 按列求平均(dim = 1):
>>> y
tensor([2.5000, 3.5000, 4.5000])
>>> z = torch.mean(a, dim = 1)
>>> z
tensor([2., 5.])