In this python numpy program, we will calculate the variance of an array using NumPy.
Steps to solve the program
- Import the numpy library as np.
- Create an array using np.array().
- Calculate the variance of the array using np.var().
- Print the output.
import numpy as np
age = np.array([20,25,21,23,26,27,26,30,24,26])
print("Variance: ",np.var(age))
Output :
Variance: 7.76