Articles

statistical functions in numpy - mean, average, var, std, max, min

statistical functions in numpy - mean, average, var, std, max, min


In this numpy tutorial,  we will discuss about:

  • statistical functions in numpy - mean
  • statistical functions in numpy - average
  • statistical functions in numpy - median
  • statistical functions in numpy - var
  • statistical functions in numpy - std
  • statistical functions in numpy - max
  • statistical functions in numpy - min

Before proceeding to statistical functions in numpy, lets see few basic things about numpy.

 

numpy stands for numeric python which is used to perform mathematical operations on arrays.

 

It is a module in which we have to import from the python. 

Syntax to import:

import numpy

We can also use alias for the module 

For example,

import numpy as np

We can directly use np to call the numpy module.

 

Numpy Array

An array is an one dimensional data structure used to store single data type data. It will only store all integer data or all string type data.or all float type data.

 

We can create an numpy array by using array() function.

Syntax:

numpy.array(elements)

where, elements are the input data elements.


numpy statistical methods: mean()

numpy mean function will return the average value of the given numpy array.

Syntax:

numpy.mean(array_data)

where, array_data is the input array.

 

Example: numpy mean function

In this numpy mean function example, we will return mean value from the given numpy array.

#importing the numpy module
import numpy 
 
 #create array with 5 integers
array_data=numpy.array([10,20,30,50,78])

#display mean
print(numpy.mean(array_data))

Output:

37.6

numpy statistical methods: average()

numpy average function will return the average value  of the given numpy array. This is similar to mean() function.

Syntax:

numpy.average(array_data)

where, array_data is the input array.

 

Example: numpy average function

In this numpy average function example, we will return average value from the given numpy array.

#importing the numpy module
import numpy 
 
 #create array with 5 integers
array_data=numpy.array([10,20,30,50,78])

#display average
print(numpy.average(array_data))

Output:

37.6

This wraps up our session on numpy average function.


numpy statistical methods: median()

numpy median function will return the median value  of the given numpy array. 

Syntax:

numpy.median(array_data)

where, array_data is the input array.

 

Example: numpy median function

In this numpy median function example, we will return median value from the given numpy array.

#importing the numpy module
import numpy 
 
 #create array with 5 integers
array_data=numpy.array([10,20,30,50,78])

#display median
print(numpy.median(array_data))

Output:

30.0

This wraps up our session on numpy median function.


numpy statistical methods: var()

numpy var function will return the variance of the given numpy array. 

Syntax:

numpy.var(array_data)

where, array_data is the input array.

 

Example: numpy var function

In this numpy var function example, we will return variance from the given numpy array.

#importing the numpy module
import numpy 
 
 #create array with 5 integers
array_data=numpy.array([10,20,30,50,78])

#display variance
print(numpy.var(array_data))

Output:

583.04

This wraps up our session on numpy var function.


numpy statistical methods: std()

numpy std function will return the standard deviation of the given numpy array. 

Syntax:

numpy.std(array_data)

where, array_data is the input array.

 

Example: numpy std function

In this numpy std function example, we will return standard deviation from the given numpy array.

#importing the numpy module
import numpy 
 
 #create array with 5 integers
array_data=numpy.array([10,20,30,50,78])

#display standard deviation
print(numpy.std(array_data))

Output:

24.146221236458512

This wraps up our session on numpy std function.


numpy statistical methods: max()

numpy max function will return the maximum value  of the given numpy array. 

Syntax:

numpy.max(array_data)

where, array_data is the input array.

 

Example: numpy max function

In this numpy max function example, we will return maximum value  from the given numpy array.

#importing the numpy module
import numpy 
 
 #create array with 5 integers
array_data=numpy.array([10,20,30,50,78])

#display maximum
print(numpy.max(array_data))

Output:

78

This wraps our session on numpy max function.


numpy statistical methods: min()

numpy min function will return the minimum value  of the given numpy array. 

Syntax:

numpy.min(array_data)

where, array_data is the input array.

 

Example: numpy min function

In this numpy min function example, we will return minimum value  from the given numpy array.

#importing the numpy module
import numpy 
 
 #create array with 5 integers
array_data=numpy.array([10,20,30,50,78])

#display minimum
print(numpy.min(array_data))

Output:

10

This wraps up our session on statistical functions in numpy or numpy statistical methods.


Numpy

Would you like to see your article here on tutorialsinhand. Join Write4Us program by tutorialsinhand.com

About the Author
Gottumukkala Sravan Kumar 171FA07058
B.Tech (Hon's) - IT from Vignan's University. Published 1200+ Technical Articles on Python, R, Swift, Java, C#, LISP, PHP - MySQL and Machine Learning
Page Views :    Published Date : Sep 01,2022  
Please Share this page

Related Articles

Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!