In this python numpy program, we will calculate the sum of each column in an array using NumPy.
Steps to solve the program
- Import the numpy library as np.
- Create an array using np.array().
- Use np.sum() and set the axis equal to 0 to calculate the sum of each column in an array.
- Print the output.
import numpy as np
x = np.array([[5, 3],
[7, 4]])
print("Sum of each column : ",np.sum(x,axis=0))
Output :
Sum of each column : [12 7]