I have a Python array, like so:
[[1,2,3], [1,2,3]]
I can add the row by doing sum(array[i]), how can I sum a column, using a
sum(array[i])
you can use zip():
zip()
In [16]: lis=[[1,2,3], ....: [1,2,3]] In [17]: map(sum,zip(*lis)) Out[17]: [2, 4, 6]
or with a simple for loops:
In [25]: for i in xrange(len(lis[0])): summ=0 for x in lis: summ+=x[i] print summ ....: 2 4 6