• Skip to secondary menu
  • Skip to main content
  • Skip to primary sidebar

Python and R Tips

Learn Data Science with Python and R

  • Home
  • Python
  • Pandas
    • Pandas 101
  • tidyverse
    • tidyverse 101
  • R
  • Linux
  • Conferences
  • Python Books
  • About
    • Privacy Policy
You are here: Home / Numpy Tips / 7 tips to get Statistical Summaries in Numpy

7 tips to get Statistical Summaries in Numpy

December 30, 2022 by cmdlinetips

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

Share this:

  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on X (Opens in new window) X

Related posts:

Default ThumbnailHow to generate random numbers from Normal distribution in Numpy Default Thumbnail12 Basic Commands with NumPy Array Default ThumbnailNumpy arange() function with examples Fun with Pandas Groupby, Agg,Pandas groupby: 13 Functions To Aggregate

Filed Under: Numpy Tips Tagged With: Numpy stat summary

Primary Sidebar

Subscribe to Python and R Tips and Learn Data Science

Learn Pandas in Python and Tidyverse in R

Tags

Altair Basic NumPy Book Review Data Science Data Science Books Data Science Resources Data Science Roundup Data Visualization Dimensionality Reduction Dropbox Dropbox Free Space Dropbox Tips Emacs Emacs Tips ggplot2 Linux Commands Linux Tips Mac Os X Tips Maximum Likelihood Estimation in R MLE in R NumPy Pandas Pandas 101 Pandas Dataframe Pandas Data Frame pandas groupby() Pandas select columns Pandas select_dtypes Python Python 3 Python Boxplot Python Tips R rstats R Tips Seaborn Seaborn Boxplot Seaborn Catplot Shell Scripting Sparse Matrix in Python tidy evaluation tidyverse tidyverse 101 Vim Vim Tips

RSS RSS

  • How to convert row names to a column in Pandas
  • How to resize an image with PyTorch
  • Fashion-MNIST data from PyTorch
  • Pandas case_when() with multiple examples
  • An Introduction to Statistical Learning: with Applications in Python Is Here
  • 10 Tips to customize ggplot2 title text
  • 8 Plot types with Matplotlib in Python
  • PCA on S&P 500 Stock Return Data
  • Linear Regression with Matrix Decomposition Methods
  • Numpy’s random choice() function

Copyright © 2025 · Lifestyle Pro on Genesis Framework · WordPress · Log in

Go to mobile version