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 may be interested in numpy, which has more advanced array features. One of which is to easily sum a column:
from numpy import array a = array([[1,2,3], [1,2,3]]) column_idx = 1 a[:, column_idx].sum() # ":" here refers to the whole array, no filtering.