Compute the mean, standard deviation, and variance of a given NumPy array Last Updated : 29 Aug, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report In NumPy, we can compute the mean, standard deviation, and variance of a given array along the second axis by two approaches first is by using inbuilt functions and second is by the formulas of the mean, standard deviation, and variance. Method 1: Using numpy.mean(), numpy.std(), numpy.var() Python import numpy as np # Original array array = np.arange(10) print(array) r1 = np.mean(array) print("\nMean: ", r1) r2 = np.std(array) print("\nstd: ", r2) r3 = np.var(array) print("\nvariance: ", r3) Output: [0 1 2 3 4 5 6 7 8 9] Mean: 4.5 std: 2.8722813232690143 variance: 8.25 Method 2: Using the formulas Python3 import numpy as np # Original array array = np.arange(10) print(array) r1 = np.average(array) print("\nMean: ", r1) r2 = np.sqrt(np.mean((array - np.mean(array)) ** 2)) print("\nstd: ", r2) r3 = np.mean((array - np.mean(array)) ** 2) print("\nvariance: ", r3) Output: [0 1 2 3 4 5 6 7 8 9] Mean: 4.5 std: 2.8722813232690143 variance: 8.25 Example: Comparing both inbuilt methods and formulas Python import numpy as np # Original array x = np.arange(5) print(x) r11 = np.mean(x) r12 = np.average(x) print("\nMean: ", r11, r12) r21 = np.std(x) r22 = np.sqrt(np.mean((x - np.mean(x)) ** 2)) print("\nstd: ", r21, r22) r31 = np.var(x) r32 = np.mean((x - np.mean(x)) ** 2) print("\nvariance: ", r31, r32) Output: [0 1 2 3 4] Mean: 2.0 2.0 std: 1.4142135623730951 1.4142135623730951 variance: 2.0 2.0 Comment More infoAdvertise with us Next Article Compute the mean, standard deviation, and variance of a given NumPy array A avengerjanus123 Follow Improve Article Tags : Python Python-numpy Python numpy-Statistics Functions Practice Tags : python Similar Reads Calculate the average, variance and standard deviation in Python using NumPy Numpy in Python is a general-purpose array-processing package. It provides a high-performance multidimensional array object and tools for working with these arrays. It is the fundamental package for scientific computing with Python. Numpy provides very easy methods to calculate the average, variance 5 min read Compute the covariance matrix of two given NumPy arrays In NumPy for computing the covariance matrix of two given arrays with help of numpy.cov(). In this, we will pass the two arrays and it will return the covariance matrix of two given arrays. Syntax: numpy.cov(m, y=None, rowvar=True, bias=False, ddof=None, fweights=None, aweights=None) Example 1: Pyth 2 min read Compute the median of the flattened NumPy array In this article, we will discuss how to compute the median of the flattened array. Median is basically that value that separates the lower half of the array with the higher half of array. Example: If there are odd numbers in an array. A = [1,2,3,4,5,6,7] Then the median element will be 7+1/2= 4th el 2 min read Create the Mean and Standard Deviation of the Data of a Pandas Series Standard Deviation is the square root of the Variance. The Standard Deviation denoted by sigma is a measure of the spread of numbers. In pandas, the std() function is used to find the standard Deviation of the series. The mean can be simply defined as the average of numbers. In pandas, the mean() fu 2 min read Calculate the mean across dimension in a 2D NumPy array We can find out the mean of each row and column of 2d array using numpy with the function np.mean(). Here we have to provide the axis for finding mean. Syntax: numpy.mean(arr, axis = None) For Row mean: axis=1 For Column mean: axis=0 Example: Python3 # Importing Library import numpy as np # creating 1 min read Like