NumPy β The Foundation of Data Science in Python
Arrays, broadcasting, and vectorised operations. Pandas is built on NumPy, and interviewers love testing it for speed and statistical reasoning.
NumPy is the engine under Pandas. These six topics cover nearly every NumPy question in data analyst interviews.
ndarray Basics
The N-dimensional array β faster and more memory-efficient than Python lists. Knowing shape, dtype, and ndim is essential.
- np.array() from lists
- shape, dtype, ndim, size
- zeros, ones, arange, linspace
Indexing & Slicing
Element, slice, boolean, and fancy indexing. 2D slicing syntax trips up many candidates.
- arr[row, col] for 2D arrays
- Boolean masks: arr[arr > 0]
- Fancy indexing with index arrays
Broadcasting
How NumPy handles operations on arrays of different shapes. The single most-asked NumPy concept in interviews.
- Scalar + array operations
- Shape compatibility rules
- Common shape errors explained
Math & Statistics
Mean, median, std, percentile, correlation β the statistical toolkit every data analyst must know.
- np.mean, median, std, var
- np.percentile and quantile
- np.corrcoef for correlations
Reshaping & Stacking
reshape, ravel, transpose, hstack, vstack β manipulate dimensions for ML pipelines and matrix operations.
- reshape(-1, 1) for column vectors
- concatenate vs stack
- flatten vs ravel difference
Random & Sampling
np.random for simulations, A/B test mocks, and bootstrap sampling β common in analytical case rounds.
- np.random.seed for reproducibility
- choice, normal, uniform
- Sampling without replacement
“Why is NumPy faster?” β demonstrate this and explain vectorisation in compiled C.
Tests percentile knowledge and boolean masking β common in EDA and data cleaning rounds.
These NumPy questions come up in analytics and data engineering interviews alike.
The functions that show up in every NumPy interview question.
| Function | Purpose |
|---|---|
| np.array(list) | Create ndarray from a Python list |
| np.zeros / ones / full | Constant-filled arrays |
| np.arange(start, stop, step) | Range as ndarray |
| np.linspace(start, stop, n) | n evenly-spaced values |
| arr.reshape(rows, cols) | Change array shape |
| arr.T / arr.transpose() | Swap rows and columns |
| np.mean / median / std | Statistical aggregates |
| np.percentile(arr, q) | q-th percentile |
| np.where(cond, x, y) | Vectorised conditional |
| np.unique(arr, return_counts) | Unique values and frequencies |
| np.concatenate / hstack / vstack | Combine arrays |
| np.random.choice / normal | Random sampling |
Ready to ace your NumPy interview?
Practise broadcasting, vectorisation, and statistical questions with a live mentor.
Book Free NumPy Session