Related Tags

communitycreator
python
numpy

# How to compute mean, median, and mode using NumPy in Python

Shreya mattegunta

In NumPy, we use special inbuilt functions to compute mean, standard deviation, and variance.

## Mean

The mean gives the arithmetic mean of the input values. It is the sum of elements divided by the total number of elements. It is given by the syntax numpy.mean() or np.mean().

import numpy as np

array = np.arange(20)
print(array)
r1 = np.mean(array)
print("\nMean: ", r1)

## Median

The median gives the middle values in the given array. Its syntax is given by np.median().

import numpy as np
array = np.arange(20)
print(array)
r1 = np.median(array)
print("\nstd: ", r1)

## Standard deviation

The standard deviation gives us the spread of distribution of array values. Standard deviation is given by the syntax np.std() or numpy.std().

import numpy as np
array = np.arange(20)
print(array)
r1 = np.std(array)
print("\nstd: ", r1)

RELATED TAGS

communitycreator
python
numpy

CONTRIBUTOR

Shreya mattegunta
RELATED COURSES

View all Courses

Keep Exploring

Learn in-demand tech skills in half the time 