Is there a numpy function to sum an array along (at most) a given axis? Along the axis, I mean something equivalent:
[x.sum() for x in arr.swapaxes(0,i)].
to sum along the i axis.
For example, the case where numpy.sum will not work directly:
>>> a = np.arange(12).reshape((3,2,2)) >>> a array([[[ 0, 1], [ 2, 3]], [[ 4, 5], [ 6, 7]], [[ 8, 9], [10, 11]]]) >>> [x.sum() for x in a]
source share