Program to calculate the sum of all columns of the NumPy array

In this python numpy program, we will calculate the sum of all columns of the NumPy array.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array using np.array().
  3. Calculate the sum of all columns of the given array using sum() and set axis equal to 0.
  4. Print the output.
				
					import numpy as np
x = np.array([[6, 5, 7],[10, 9, 1],[7, 8, 2]])

print("Sum of all columns: ",x.sum(axis=0))
				
			

Output :

				
					Sum of all columns:  [23 22 10]
				
			

copy data from a given array to another array.

calculate averages without NaNs along a row.

Leave a Comment