w3resource logo
Python Exercises

Python NumPy: Calculate mean across dimension, in a 2D numpy array

Python NumPy Math, Statistics, Trigonometry and Linear algebra: Exercise-19 with Solution

Write a Python program to calculate mean across dimension, in a 2D numpy array.

Sample Solution:-

Python Code:

import numpy as np
x = np.array([[10, 30], [20, 60]])
print("Original array:")
print("Mean of each row:")
print("Mean of each column:")

Sample Output:

Original array:                                                        
[[10 30]                                                               
 [20 60]]                                                              
Mean of each row:                                                      
[ 15.  45.]                                                            
Mean of each column:                                                   
[ 20.  40.]

Python Code Editor:

Improve this sample solution and post your code through Disqus