Question #612

In Python, how to sum columns of a NumPy array?

Answer

To sum the columns of a NumPy array, the best option is to use the numpy.sum() method by specifying the axis option:

>>> import numpy as np
>>> a = np.array([[1, 2], [3, 4], [5, 6]])
>>> a.sum(axis=0)
array([ 9, 12])


2 events in history
Answer by Alphonsio 01/11/2021 at 03:39:59 PM

To sum the columns of a NumPy array, the best option is to use the numpy.sum() method by specifying the axis option:

>>> import numpy as np
>>> a = np.array([[1, 2], [3, 4], [5, 6]])
>>> a.sum(axis=0)
array([ 9, 12])


Question by Alphonsio 01/11/2021 at 03:36:14 PM
In Python, how to sum columns of a NumPy array?
# ID Query URL Count

Icons proudly provided by Friconix.