7 tips to get Statistical Summaries in Numpy

In this post we will learn about 5 handy statistical summary functions in Numpy. Numpy offers a variety of statistical summary functions to help analyse understand data. Numpy’s summary functions allow you to calculate, quickly using vectorized operations. In this post we will learn how to use some of the most commonly used statistical summary functions in Numpy, such as mean, median, and standard deviation. We’ll provide some examples to help you get started.

Let us load Numpy.

import numpy as np

1. Numpy mean() function

The first statistical summary function we’ll discuss is “mean.” The mean is the average of a set of numbers, and it is calculated by adding all of the numbers together and then dividing by the number of items in the set. To find the mean of an array in Numpy, you can use the “mean” function, like this:

data = np.array([1, 2, 3, 4, 5])
mean = np.mean(data)
print(mean) 
3.0

In this example, the mean of the data set is 3.0, which is the average of all of the numbers in the array.

2. Numpy median() function

Another common statistical summary function is “median.” The median is the middle number in a set of numbers. To find the median of an array in Numpy, you can use the “median” function, like this:

data = np.array([1, 2, 3, 4, 5])
median = np.median(data)
print(median) 
3.0

In the above example, the median of the data set is 3.0, which is the middle number in the array.

3. Numpy mode() function

Another useful statistical summary function is the mode function. The mode is the most frequently occurring value in an array.

For example, if we have an array of numbers [1, 2, 3, 3, 4, 5], the mode would be 3. To use the mode function in Numpy, we can do the following:

data = np.array([1, 2, 3, 3, 4, 5])
mode = np.mode(data)
print(mode)
3

4. Numpy var() function

Another important statistical summary function is the variance function. The variance measures the spread of an array of numbers around the mean.

For example, if we have an array of numbers [1, 2, 3, 4, 5], the variance would be 2.5. Here is an example of using variance function in Numpy.

data = np.array([1, 2, 3, 4, 5])
variance = np.var(data)
print(variance)

2.5

5. Numpy std() function

Standard deviation is another statistical summary function that is commonly used in Numpy. Standard deviation is a measure of how spread out the data is around the mean, and it is calculated by taking the square root of the variance. To find the standard deviation of an array in Numpy, you can use the “std” function, like this:

data = np.array([1, 2, 3, 4, 5])
std = np.std(data)
print(std) 
1.5811388300841898

In this example, the standard deviation of the data set is 1.58, which indicates that the data is fairly spread out around the mean.

6. Numpy min() and max() functions

Numpy’s, min() and max() functions can calculate the minimum and maximum values of an array quickly.

Here. is the code to get minimum and maximum values of a 1-D array.

a = np.array([1, 2, 3, 4, 5])
minimum = np.min(a)
maximum = np.max(a)

print(minimum)
1

print(maximum) 
5

7. Numpy argmin() and argmax() functions

Sometimes you might wanmt to know the indices of minimum and maximum value in 1-D array. Numppy’s argmin() and argmax() functions calculate the indices of the minimum and maximum values of an array, respectively.

Here is an example of using argmmin() and argmax() on 1-D array.

a = np.array([1, 2, 3, 4, 5])
min_index = np.argmin(a)
max_index = np.argmax(a)
print(min_index)  
0
print(max_index) 

4