Solved by Nikronic in post #2 
              
              
                Hi, 
Using built-in functions, it would be like this: 
num_channels = 10
x = torch.randn(2, num_channels, 4, 5)
result = torch.sum(x, dim=[0, 2, 3])

torch.sum accepts a parameter dim which can be a list. If you pass a list, it will reduce the tensor over all the indices in dim. For instance, 
x = t…