Pytorch - add rows of a 2D tensor element-wise
I have the following tensor :

ts = torch.tensor([[1,2,3],[4,6,7],[8,9,10]])
&gt; tensor([[ 1,  2,  3],
    [ 4,  6,  7],
    [ 8,  9, 10]])


I am looking for a pytorch generic operation that adds all rows element-wise like that:

ts2 = ts[0]+ts[1]+ts[2]
print(ts2)
&gt; tensor([13, 17, 20])


In reality, the number of rows corresponds to the batch size that vary. 

You can sum over an axis/dimension like so:

torch.sum(ts, dim=0)

