The NumPy library (Numerical Python) is the foundation of scientific computing in Python. Its core type is the ndarray: a multidimensional array of elements that share one dtype.
Core concepts
- ndarray — n-dimensional array with
shape,dtype, andndim - Vectorization — apply operations to whole arrays without Python loops
- Broadcasting — align differently shaped arrays for element-wise math
- ufuncs — universal functions (
np.add,np.sqrt) that run in C
Typical use cases
- Image and signal processing (2D/3D arrays)
- Feature matrices for machine learning
- Simulation and Monte Carlo sampling
- Linear algebra and statistics
Import convention
import numpy as np
x = np.zeros((2, 3))
print(x.shape) # (2, 3)
Important interview questions and answers
- Q: Homogeneous vs heterogeneous?
A: All elements share one dtype—unlike Python lists that can mix int, str, and objects. - Q: Why import as np?
A: Universal convention—readable and matches documentation across the ecosystem.
Self-check
- Name four core NumPy concepts.
- Give one real-world use case for ndarrays.
Tip: Always print shape and dtype when debugging arrays.
Interview prep
- Homogeneous?
All elements share one dtype—unlike Python lists.
- Vectorization?
Operations apply to whole arrays via ufuncs in compiled code.