v Calculate The Average, Variance, And Standard Deviation - Machine Learning

Calculate The Average, Variance, And Standard Deviation

Preliminaries

# Load library
import numpy as np

Create Matrix

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

Calculate Mean

# Return mean
np.mean(matrix)
5.0

Calculate Variance

# Return variance
np.var(matrix)
6.666666666666667

Calculate Standard Deviation

# Return standard deviation
np.std(matrix)
2.5819888974716112