This is much simpler if you use Numpy:
import numpy as np data = [[[5, 10, 30, 24, 100], [1, 9, 25, 49, 81]], [[15, 10, 10, 16, 70], [10, 1, 25, 11, 19]], [[34, 20, 10, 10, 30], [9, 20, 25, 30, 80]]] a = np.array(data) print a.sum(axis=0)
Output:
[[ 54, 40, 50, 50, 200], [ 20, 30, 75, 90, 180]]
Similarly:
In [5]: a.sum(axis=1) Out[5]: array([[ 6, 19, 55, 73, 181], [ 25, 11, 35, 27, 89], [ 43, 40, 35, 40, 110]]) In [6]: a.sum(axis=2) Out[6]: array([[169, 165], [121, 66], [104, 164]]) In [7]: a.sum() Out[7]: 789