import torch
x = torch.arange(24).view(2, 3, 4).float()
y = x.mean(0)
print("x.shape:", x.shape)
print("x:")
print(x)
print("y.shape:", y.shape)
print("y:")
print(y)
如果对i维度求均值,则就是拿出不同i维度的值求均值
如对2求均值,就是对行求均值,即对不同行求和,然后除行数
如果是多个 维度一起求均值
则先求低维度,再求搞维度
import torch
x = torch.arange(24).view(2, 3, 4).float()
y = x.mean([0,1])
print("x.shape:", x.shape)
print("x:")
print(x)
print("y.shape:", y.shape)
print("y:")
print(y)
先求dim=1,再求dim=0
标签:tensor,torch,维度,shape,print,mean From: https://www.cnblogs.com/MittyWalter/p/17844177.html