Compute mean, median, standard deviation and variance in NumPy using the axis parameter

Quick Overview

Asks how to compute the mean, median, standard deviation and variance of an array with NumPy and how the axis argument changes the result. Tests reading result shapes, choosing the sample or population formula, and handling missing values.

Compute mean, median, standard deviation and variance in NumPy using the axis parameter

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

Explain how to calculate common descriptive statistics like mean, median, standard deviation, and variance using `NumPy`, specifically addressing the `axis` parameter. ```hint Try a small array Work out the shape of the result for each value of `axis` on a 2-by-3 array, and check which divisor `np.std` uses when you pass no extra arguments. ``` ### What a Strong Answer Covers - The NumPy functions for each statistic and what each one computes - How `axis=None`, `axis=0` and `axis=1` change what is aggregated and the shape of the result - The default `ddof` of `np.std` and `np.var` and when to change it - How missing values are handled, including the NaN-safe variants ### Follow-up Questions - Why do `np.std(x)` and `pd.Series(x).std()` give different numbers for the same data? - What does `keepdims=True` do, and when do you need it, for example when standardizing each row? - How would you compute one statistic over two axes of a 3D array at once?

Overview: Asks how to compute the mean, median, standard deviation and variance of an array with NumPy and how the axis argument changes the result. Tests reading result shapes, choosing the sample or population formula, and handling missing values.

General logo
General
Nov 25, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

Explain how to calculate common descriptive statistics like mean, median, standard deviation, and variance using NumPy, specifically addressing the axis parameter.

What a Strong Answer Covers Guidance

  • The NumPy functions for each statistic and what each one computes
  • How axis=None , axis=0 and axis=1 change what is aggregated and the shape of the result
  • The default ddof of np.std and np.var and when to change it
  • How missing values are handled, including the NaN-safe variants

Follow-up Questions Guidance

  • Why do np.std(x) and pd.Series(x).std() give different numbers for the same data?
  • What does keepdims=True do, and when do you need it, for example when standardizing each row?
  • How would you compute one statistic over two axes of a 3D array at once?