NumPy: Compute the average, variance, standard deviation of an array of 1000 elements
NumPy Mathematics: Exercise-20 with Solution
Write a NumPy program to create a random array with 1000 elements and compute the average, variance, standard deviation of the array elements.
import numpy as np x = np.random.randn(1000) print("Average of the array elements:") mean = x.mean() print(mean) print("Standard deviation of the array elements:") std = x.std() print(std) print("Variance of the array elements:") var = x.var() print(var)
Average of the array elements: -0.0255137240796 Standard deviation of the array elements: 0.984398282476 Variance of the array elements: 0.969039978542
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a NumPy program to calculate mean across dimension, in a 2D numpy array.
Next: Write a NumPy program to compute the trigonometric sine, cosine and tangent array of angles given in degrees.
What is the difficulty level of this exercise?
Test your Python skills with w3resource's quiz
Python: Tips of the Day
Getting rid of unwanted characters:
You can get rid of whitespaces or any specific character using strip methods in Python. You can use either plain strip for both sides, lstrip for the left side and rstrip for the right side only.
str="+++Welcome python+++" str.strip() print(str)
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework