Question #375   Submitted by Answiki on 01/11/2021 at 03:36:14 PM UTC

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

Answer   Submitted by Answiki on 01/11/2021 at 03:39:59 PM UTC

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 Answiki on 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 Answiki 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.