What is Sample Variance and How to Compute it in Numpy – Numpy Tutorial

By | September 15, 2019

Sample variance formula is:

sampel variance formula

Variance formula is:

variance formula

To calculate sample variance of a matrix, you can compute variance first.

Preliminaries

import numpy as np

Create a matrix

m = np.array([[2, 3, 5],[1, 4, 6]])

The result is:

array([[2, 3, 5],
       [1, 4, 6]])

Compute variance of matrix

v = np.var(m)

The result is:

2.9166666666666665

Compute sample variance

sv = v * (m.size/((m.size - 1)*1.0))

The result is:

3.4999999999999996

Leave a Reply