
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Get Mean of a Matrix in Python
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.
Advertisements