Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Numpy exercise
  • pandas
  • Matplotlib
  • Data visulisation
  • EDA
  • Machin Learning
  • Deep Learning
  • NLP
  • Data science
  • ML Tutorial
  • Computer Vision
  • ML project
Open In App
Next Article:
Calculate the mean across dimension in a 2D NumPy array
Next article icon

Calculate the mean across dimension in a 2D NumPy array

Last Updated : 29 Aug, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report

We can find out the mean of each row and column of 2d array using numpy with the function np.mean(). Here we have to provide the axis for finding mean.

Syntax: numpy.mean(arr, axis = None)

For Row mean: axis=1

For Column mean: axis=0

Example:

Python3
# Importing Library import numpy as np  # creating 2d array arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])  # Calculating mean across Rows row_mean = np.mean(arr, axis=1)  row1_mean = row_mean[0] print("Mean of Row 1 is", row1_mean)  row2_mean = row_mean[1] print("Mean of Row 2 is", row2_mean)  row3_mean = row_mean[2] print("Mean of Row 3 is", row3_mean)   # Calculating mean across Columns column_mean = np.mean(arr, axis=0)  column1_mean = column_mean[0] print("Mean of column 1 is", column1_mean)  column2_mean = column_mean[1] print("Mean of column 2 is", column2_mean)  column3_mean = column_mean[2] print("Mean of column 3 is", column3_mean) 

Output:

Mean of Row 1 is 2.0  Mean of Row 2 is 5.0  Mean of Row 3 is 8.0  Mean of column 1 is 4.0  Mean of column 2 is 5.0  Mean of column 3 is 6.0  

Next Article
Calculate the mean across dimension in a 2D NumPy array

V

vasu_gupta
Improve
Article Tags :
  • Python
  • Python-numpy
  • Python numpy-program
  • Python numpy-Statistics Functions
Practice Tags :
  • python

Similar Reads

    Calculate the sum of all columns in a 2D NumPy array
    Let us see how to calculate the sum of all the columns in a 2D NumPy array.Method 1 : Using a nested loop to access the array elements column-wise and then storing their sum in a variable and then printing it.Example 1:   Python3 # importing required libraries import numpy # explicit function to com
    3 min read
    Calculating the sum of all columns of a 2D NumPy array
    Let us see how to calculate the sum of all the columns of a 2 dimensional NumPy array. Example : Input : [[1, 2, 3, 4, 5], [5, 6, 7, 8, 9], [2, 1, 5, 7, 8], [2, 9, 3, 1, 0]] Output : [10, 18, 18, 20, 22] Input : [[5, 4, 1, 7], [0, 9, 3, 5], [3, 2, 8, 6]] Output : [8, 15, 12, 18] Approach 1 : We will
    2 min read
    Accessing Data Along Multiple Dimensions Arrays in Python Numpy
    NumPy (Numerical Python) is a Python library that comprises of multidimensional arrays and numerous functions to perform various mathematical and logical operations on them. NumPy also consists of various functions to perform linear algebra operations and generate random numbers. NumPy is often used
    3 min read
    Calculate the sum of the diagonal elements of a NumPy array
    Sometimes we need to find the sum of the Upper right, Upper left, Lower right, or lower left diagonal elements. Numpy provides us the facility to compute the sum of different diagonals elements using numpy.trace() and numpy.diagonal() method. Method 1: Finding the sum of diagonal elements using nump
    2 min read
    Convert 2D float array to 2D int array in NumPy
    Converting a 2D float array to a 2D integer array in NumPy is a straightforward process using the astype() method. This conversion can be useful in various data analysis and scientific computing tasks where integer data types are required or where memory efficiency is essential. In this article, we
    8 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences