在二维的操作实例 以及 输出的结果
>> x = torch.tensor([ [1, 2, 3], [4, 5, 6] ])
>> x.shapetorch.Size([2, 3])
>> torch.sum(x, dim=0)tensor([5, 7, 9])
>> torch.sum(x, dim=1)tensor([6, 15])
在三维的操作 以及 输出结果 动态演示
>> y = torch.tensor([ [ [1, 2, 3], [4, 5, 6] ], [ [1, 2, 3], [4, 5, 6] ], [ [1, 2, 3], [4, 5, 6] ] ])
>> y.shapetorch.Size([3, 2, 3]) >> torch.sum(y, dim=0)
tensor([[ 3, 6, 9], [12, 15, 18]])
>> torch.sum(y, dim=0)
tensor([[ 3, 6, 9], [12, 15, 18]])
>> torch.sum(y, dim=1)
tensor([[5, 7, 9], [5, 7, 9], [5, 7, 9]])
>> torch.sum(y, dim=2)
tensor([[ 6, 15], [ 6, 15], [ 6, 15]])
标签:dim,15,tensor,sum,torch,Understanding,PyTorch,dimensions From: https://www.cnblogs.com/wangkangxuexi/p/17044006.html