Title: Calculate The Average, Variance, And Standard Deviation
Slug: calculate_average_variance_and_standard_deviation
Summary: How to calculate the average, variance, and standard deviation of an array in Python.
Date: 2017-09-04 12:00
Category: Machine Learning
Tags: Vectors Matrices Arrays
Authors: Chris Albon

Preliminaries


In [1]:
# Load library
import numpy as np

Create Matrix


In [2]:
# Create matrix
matrix = np.array([[1, 2, 3],
                   [4, 5, 6],
                   [7, 8, 9]])

Calculate Mean


In [3]:
# Return mean
np.mean(matrix)


Out[3]:
5.0

Calculate Variance


In [4]:
# Return variance
np.var(matrix)


Out[4]:
6.666666666666667

Calculate Standard Deviation


In [5]:
# Return standard deviation
np.std(matrix)


Out[5]:
2.5819888974716112