5/1242
Statistical Operations · Page 1 of 1

Descriptive Statistics with NumPy

20 min Intermediate

Statistical Operations

Moving Beyond Basic Averages

In Data Science, understanding the spread of your data is just as important as the average.

Key NumPy Stats Methods

  • np.mean(): Average
  • np.median(): Middle value (robust to outliers)
  • np.std(): Standard Deviation (spread)
  • np.var(): Variance (std squared)
  • np.percentile(): Find thresholds (e.g., top 10%)

The axis Argument

When working with 2D arrays (matrices), you can calculate stats per row or per column:

  • axis=0: Operate down the rows (result per column)
  • axis=1: Operate across the columns (result per row)
matrix = np.array([[1, 2, 3],
                   [4, 5, 6]])
matrix.mean(axis=0) # → [2.5, 3.5, 4.5] (column means)
main.py
Loading...
OUTPUT
Click "Run Code" to execute…