# How to sum up subelements of a list of unknown length

I'm simply looking for the {}+{} function for sublist elements of a list: (Parallel sums of elements)

c = {{1, 2, 3, 4}, {8, 7, 6, 5}};
Plus[c]
Mean[c]
desired={9, 9, 9, 9}


Where Mean does directly what it's supposed to, unfortunately Plus doesn't. I tried Take and Part but they both do not seem to work here . Additionally, my c consists of a varying number of elements. I tried to work with Length[c] and Range .. ({}+{} is no solution as list element number varies) thank you for help!!

Use either

Plus@@c


or

Total[c]

• For completeness: if one treats the list of lists as a matrix, Total[c] and Total[c, {1}] sums columns, Total[c, {2}] sums rows, and Total[c, 2] sums all elements. Commented Feb 15, 2012 at 23:29
• @J.M. Good points. For once, I did not try to be complete :) Commented Feb 15, 2012 at 23:35
• Leonid, are you ill? :o) Commented Feb 16, 2012 at 5:10
• @Mr.Wizard Looks like that :) Commented Feb 16, 2012 at 13:36

Before version 5, I used Tr a lot for summing vectors as Total wasn't available:

c = {{1, 2, 3, 4}, {8, 7, 6, 5}};
Tr /@ Transpose[c]

(*
==> {9, 9, 9, 9}
*)


Use

Apply[Plus, {{1, 2, 3, 4}, {8, 7, 6, 5}}]
(*
==> {9, 9, 9, 9}
*)


or its shortcut

Plus @@ {{1, 2, 3, 4}, {8, 7, 6, 5}}


Another way is

MapThread[Plus, {{1, 2, 3, 4}, {8, 7, 6, 5}}]


Here is another method that I hope will be instructive.

Sum[i, {i, c}]


{9, 9, 9, 9}

In TraditionalForm: