NumPy provides ndarray storage, broadcasting, ufuncs, and basic np.linalg. SciPy adds domain libraries: richer statistics, optimizers, sparse LA, ODEs, and signal processing.
Division of labor
| Task | NumPy | SciPy |
|---|---|---|
| Array creation, reshape, broadcast | Core | Uses NumPy |
| Mean, std on arrays | np.mean, np.std | stats.describe, distributions |
| Linear solve small dense | np.linalg.solve | linalg.solve, sparse solvers |
| Hypothesis test p-value | — | stats.ttest_ind |
| Minimize function | — | optimize.minimize |
| FFT | np.fft | signal filters, windows |
When to reach for SciPy
- You need a named probability distribution or formal test
- You are fitting parameters or finding roots numerically
- Matrices are large and sparse
- You integrate ODEs or apply digital filters
Same array, richer ops
import numpy as np
from scipy import stats
a = np.array([1.0, 2.0, 3.0, 4.0, 5.0])
print('NumPy mean:', a.mean())
print('SciPy describe:', stats.describe(a))
Important interview questions and answers
- Q: Can NumPy replace SciPy?
A: For simple aggregates, yes. For distributions, tests, optimize, sparse LA—use SciPy. - Q: Does SciPy duplicate np.linalg?
A: Overlaps for small dense problems; SciPy adds specialized decompositions and sparse tools.
Self-check
- Give one task NumPy handles alone vs one that needs SciPy.
- What does stats.describe add beyond np.mean?
Tip: Use NumPy for array plumbing; reach for SciPy when you need a named test, optimizer, or sparse solver.
Interview prep
- When SciPy?
Distributions, hypothesis tests, optimization, sparse LA, ODEs, filters.
- When NumPy alone?
Basic aggregates, array creation, broadcasting, simple np.linalg on small dense.