7. Write a Python Numpy program to calculate the mean, standard deviation and variance of the given array in the following output.
The output is:
Expected Answer:
Initial array: [1 2 3 4 5]
Mean: 3.0
Standard deviation: 1.707825127659933
Variance: 2.9166666666666665
Sample Answer 1:
import numpy as np a = np.arange(1, 6) print("Initial array:", a) b1 = np.mean(a) print("\nMean: ", b1) c1 = np.std(x) print("\nStandard deviation: ", c1) d1= np.var(x) print("\nVariance: ", d1)
Sample Answer 2:
import numpy as np a = np.arange(1, 6) print("Initial array:", a) b1 = np.average(a) print("\nMean: ", b1) c1 = np.sqrt(np.mean((x - np.mean(x)) ** 2 )) print("\nStandard deviation: ", c1) d1 = np.mean((x - np.mean(x)) ** 2 ) print("\nVariance: ", d1)
More Exercises:
Python String ExercisesMore Numpy Exercises:
Numpy String ExercisesMore Pandas Exercises:
Pandas Series ExercisesMore Tutorials:
Python Installation - Linux (Ubuntu)