NumPy
raw JSON → 2.4.3 verified Tue May 12 auth: no python install: verified quickstart: verified
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.
pip install numpy Common errors
error ValueError: numpy.ufunc size changed, may indicate binary incompatibility. Expected XXX from C header, got YYY from PyObject ↓
cause This error occurs when a Python package (like SciPy, scikit-learn, or others) that depends on NumPy was compiled against a different NumPy ABI version than the one currently installed, often due to the breaking changes introduced in NumPy 2.0.
fix
Upgrade the affected downstream package to a version compiled against NumPy 2.x, or downgrade NumPy to a version compatible with the package (e.e.
pip install 'numpy<2'). If it's a locally built package, it needs to be recompiled against the current NumPy 2.x installation. error ImportError: numpy.core.multiarray failed to import ↓
cause This often indicates an incompatibility between NumPy and other installed libraries, a corrupted NumPy installation, or multiple conflicting NumPy versions in the environment, which is particularly common with NumPy 2.0's ABI changes.
fix
Try uninstalling and reinstalling NumPy (
pip uninstall numpy && pip install numpy). If the issue persists, explicitly upgrade or downgrade NumPy to a compatible version for your other packages (pip install 'numpy<2' or pip install numpy --upgrade), or create a clean virtual environment and reinstall all dependencies. error ModuleNotFoundError: No module named 'numpy' ↓
cause NumPy is either not installed in the currently active Python environment, or the Python interpreter being used cannot locate the installed NumPy module, often due to multiple Python installations or improper environment setup.
fix
Install NumPy using pip (
pip install numpy). If already installed, ensure you are running your script with the Python interpreter where NumPy is installed, or activate the correct virtual environment. error AttributeError: module 'numpy' has no attribute 'rank' ↓
cause This error occurs because the `numpy.rank` function was deprecated and later removed in NumPy 2.0 (and earlier, deprecated in 1.9.0) to avoid confusion with `numpy.linalg.matrix_rank`. Similarly, other attributes like `numpy.product` were also removed or moved.
fix
Replace
np.rank(array) with array.ndim or np.ndim(array) to get the number of dimensions. For other removed attributes, consult the NumPy 2.0 migration guide for the correct replacement (e.g., np.prod for np.product). error TypeError: ufunc 'add' did not contain a loop with signature matching types ↓
cause This error indicates an attempt to perform a universal function (ufunc) operation (like addition or subtraction) on arrays with incompatible or mixed data types, or when the data type promotion rules (which changed in NumPy 2.0, NEP 50) result in an unexpected type.
fix
Ensure all array elements have a consistent data type before performing the operation, typically by explicitly casting them using the
.astype() method (e.g., arr.astype(float)). For type promotion issues in NumPy 2.0, explicitly cast to the desired precision or use Python scalars. 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. ↓
fix Upgrade all binary dependencies to versions built against NumPy 2.x. Check https://github.com/numpy/numpy/issues/24300 for ecosystem compatibility status.
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. ↓
fix Replace with explicit dtypes: np.float_ → np.float64, np.int_ → np.intp, np.complex_ → np.complex128, np.bool_ → np.bool_, np.Inf → np.inf, np.NAN → np.nan. Use ruff --select NPY201 to auto-fix.
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. ↓
fix Audit mixed-precision arithmetic. Explicitly cast where float64 precision is required: np.float64(3) + arr or arr.astype(np.float64).
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. ↓
fix Access all public members from the main np namespace. Never import from np.core or np._core directly.
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. ↓
fix Use np.random.default_rng(seed) to create a Generator. Replace np.random.randn(n) with rng.standard_normal(n), np.random.randint(a, b) with rng.integers(a, b).
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. ↓
fix Use Python float or np.float64 explicitly. Same for np.int → int or np.int64, np.complex → complex or np.complex128.
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. ↓
fix For variable-length strings: arr = np.array(['hello', 'world'], dtype=np.dtypes.StringDType()). np.string_ creates fixed-width byte arrays.
Install compatibility verified last tested: 2026-05-12
python os / libc status wheel install import disk
3.10 alpine (musl) - - 0.20s 89.3M
3.10 slim (glibc) - - 0.16s 86M
3.11 alpine (musl) - - 0.33s 96.8M
3.11 slim (glibc) - - 0.28s 92M
3.12 alpine (musl) - - 0.26s 85.2M
3.12 slim (glibc) - - 0.28s 81M
3.13 alpine (musl) - - 0.22s 84.6M
3.13 slim (glibc) - - 0.27s 80M
3.9 alpine (musl) - - 0.18s 97.1M
3.9 slim (glibc) - - 0.17s 96M
Imports
- numpy wrong
import numpy as np arr = np.array([1.0, 2.0], dtype=np.float_) # np.float_ removed in 2.0 scalar = np.float(3.14) # np.float removed in 1.24correctimport numpy as np arr = np.array([1.0, 2.0], dtype=np.float64) scalar = np.float64(3.14) - random wrong
np.random.seed(42) arr = np.random.randn(100) # legacy API — deprecated in favor of Generatorcorrectrng = np.random.default_rng(seed=42) arr = rng.standard_normal(100)
Quickstart verified last tested: 2026-04-23
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,)