How to find mean median and mode in Python using NumPy

You can find the mean median and mode in Python using NumPy with the following code. If you want to learn Python then I will highly recommend you to read This Book.

How to find mean median and mode in Python using NumPy
How to find mean median and mode in Python using NumPy

Mean

You can easily find the mean with the help of the np.mean() method.

import numpy as np
a = [1,2,2,4,5,6]
print(np.mean(a))

Median

You can easily find the median with the help of the np.median() method.

import numpy as np
a = [1,2,2,4,5,6]
print(np.median(a))

Mode

For mode, you have to import stats from the SciPy library because there is no direct method in NumPy to find mode.

from scipy import stats
a = [1,2,2,2,4,5,6,6]
x = stats.mode(a)
print(x)

People are also reading:

Best Python Books

What is Computer Vision? Examples, Applications, Techniques

Top 10 Computer Vision Books with Python

Books for Machine Learning (ML)

Free Learning Resources

Leave a Comment

Your email address will not be published.