Calculate the sum of each column in an array using NumPy.

In this python numpy program, we will calculate the sum of each column in an array using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array using np.array().
  3. Use np.sum() and set the axis equal to 0 to calculate the sum of each column in an array.
  4. 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]
				
			

calculate the sum of each row in an array.

calculate the inner/dot product of two vectors.

Leave a Comment