Python Practice › NumPy Programs › Program 93
Variance
Write a NumPy program to calculate the variance of an array.
Input
[2, 4, 4, 4, 5, 5, 7, 9]
Output
4.0
Approach
np.var.
Solution
import numpy as npprint(np.var([2, 4, 4, 4, 5, 5, 7, 9]))Output
4.0
Learn the concept
New to this topic? Read the lesson, then come back.