

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python – Get Matrix Mean
When it is required to get the mean of the matrix elements, the ‘mean’ method from the ‘Numpy’ package is used after it has been imported into the environment.
Example
Below is a demonstration of the same −
import numpy as np my_matrix = np.matrix('[24, 41; 35, 25]') print("The matrix is : " ) print(my_matrix) my_result = my_matrix.mean() print("The result is : ") print(my_result)
Output
The matrix is : [[24 41] [35 25]] The result is : 31.25
Explanation
The required packages are imported into the environment.
A matrix is created using the Numpy package.
It is displayed on the console.
The mean of the matrix is determined using the ‘mean’ method.
This is assigned to a variable.
It is displayed as the output on the console.
- Related Questions & Answers
- Get Nth Column of Matrix in Python
- Mean and Median of a matrix in C++
- Find the mean vector of a Matrix in C++
- Number of elements greater than modified mean in matrix in C++
- How to get the mean of a specific column in a dataframe in Python?
- Implement mean shift algorithm in Python
- Find Rolling Mean – Python Pandas
- Python – Mean deviation of Elements
- Python - Cumulative Mean of Dictionary keys
- How to divide the row values by row mean in R matrix?
- Get the trace of a matrix with Einstein summation convention in Python
- Find Harmonic mean using Arithmetic mean and Geometric mean using C++.
- Python – Convert Integer Matrix to String Matrix
- Matrix manipulation in Python
- Initialize Matrix in Python
Advertisements