ipdb> outputs.size() torch.Size([10, 100]) ipdb> print sum(outputs,0).size(),sum(outputs,1).size(),sum(outputs,2).size() (100L,) (100L,) (100L,)
How do I sum over the columns instead?
sum. Returns the sum of all elements in the input tensor.
The simplest and best solution is to use torch.sum()
.
To sum all elements of a tensor:
torch.sum(outputs) # gives back a scalar
To sum over all rows (i.e. for each column):
torch.sum(outputs, dim=0) # size = [1, ncol]
To sum over all columns (i.e. for each row):
torch.sum(outputs, dim=1) # size = [nrow, 1]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With