How to calculate sum of columns and rows in Numpy Python library.

In Numpy your can quickly sum columns and rows of your array.

To calculate sum of array columns just add 0 parameter.

import numpy as np my_array = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) print(my_array) print("Sum of columns equals: ", np.sum(my_array, 0))

Similarly to sum up rows add 1 as a parameter.

import numpy as np my_array = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) print(my_array) print("Sum of rows equals: ", np.sum(my_array, 1))

To sum up every array element just remove parameters.

import numpy as np my_array = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) print(my_array) print("Sum of every elements of your array equals: ", np.sum(my_array))