NumPy
Fundamental package for numerical computing in Python. Current version is 2.4.3 (Mar 2026). NumPy 2.0 (Jun 2024) was a landmark major release with ABI breakage, ~100 removed namespace members, and type promotion changes (NEP 50). Packages built against NumPy 1.x will not import with NumPy 2.x.
Warnings
- breaking ABI break in NumPy 2.0. Packages built against NumPy 1.x will not import with NumPy 2.x — raises ImportError about binary incompatibility. This affected TensorFlow, PyTorch, scipy, and many others at release.
- breaking ~100 np namespace members removed in 2.0 including: np.float_, np.int_, np.complex_, np.object_, np.bool_, np.str_, np.long, np.unicode_, np.cfloat, np.Inf, np.Infinity, np.NAN, np.PINF, np.NINF. AttributeError on first use.
- breaking Type promotion rules changed (NEP 50) in NumPy 2.0. Scalar precision is now preserved: np.float32(3) + 3. now returns float32 instead of float64. Code with mixed scalar/array operations may silently produce lower-precision results.
- breaking np.core namespace renamed to np._core (private) in 2.0. Code importing from np.core (common in older library code) will raise ImportError.
- deprecated Legacy random API (np.random.seed, np.random.rand, np.random.randn, np.random.randint etc.) is not formally deprecated yet but the new Generator API is strongly preferred. Legacy API has known issues with reproducibility in multiprocessing.
- gotcha np.float (Python built-in alias) was removed in NumPy 1.24, not 2.0. Already gone for 2+ years but still extremely common in LLM-generated code.
- gotcha np.string_ is still available but is bytes-based (fixed-width). For variable-length string arrays use np.dtypes.StringDType() (new in 2.0) or Python object arrays.
Install
-
pip install numpy
Imports
- numpy
import numpy as np arr = np.array([1.0, 2.0], dtype=np.float64) scalar = np.float64(3.14)
- random
rng = np.random.default_rng(seed=42) arr = rng.standard_normal(100)
Quickstart
import numpy as np # Array creation arr = np.array([1, 2, 3, 4], dtype=np.float64) matrix = np.zeros((3, 4), dtype=np.float32) # Operations result = arr * 2 + 1 dot = np.dot(matrix.T, matrix) # Random (new API) rng = np.random.default_rng(seed=42) samples = rng.standard_normal((100, 10)) # Type check print(arr.dtype) # float64 print(arr.shape) # (4,)