Registry / data / numpy

numpy

JSON →
library2.4.3pypypi✓ verified 53d ago

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.

dataai-ml
pip install numpy
Install & Compatibility
Where this runs
tested against v2.2.6 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.925 runs
installs and imports cleanly · install 0.0s · import 0.234s · 89.3MB
glibc
py 3.103.925 runs
installs and imports cleanly · install 3.6s · import 0.242s · 86MB
89MB installed
● package 89MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

numpy
import numpy as np arr = np.array([1.0, 2.0], dtype=np.float64) scalar = np.float64(3.14)
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.24
np.float_, np.int_, np.complex_, np.bool_, np.object_, np.str_ aliases all removed in NumPy 2.0. Use np.float64, np.int64, np.complex128, np.bool_ → bool, etc.
random
rng = np.random.default_rng(seed=42) arr = rng.standard_normal(100)
np.random.seed(42) arr = np.random.randn(100) # legacy API — deprecated in favor of Generator
np.random.seed() + np.random.randn() is the legacy RandomState API. The new Generator API (np.random.default_rng()) is preferred and provides better statistical properties.

Basic array creation and operations. Use new random Generator API.

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,)
Debug
Known issues
breakingABI 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.
affects: >= 2.0
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.
affects: >= 2.0
breakingType 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).
affects: >= 2.0
breakingnp.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.
affects: >= 2.0
deprecatedLegacy 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).
affects: all
gotchanp.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.
affects: >= 1.24
gotchanp.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.
affects: all
Errors
Common errors & fixes
ValueError: numpy.ufunc size changed, may indicate binary incompatibility. Expected XXX from C header, got YYY from PyObject
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.
ImportError: numpy.core.multiarray failed to import
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.
ModuleNotFoundError: No module named 'numpy'
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.
AttributeError: module 'numpy' has no attribute 'rank'
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`).
TypeError: ufunc 'add' did not contain a loop with signature matching types
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.
Upgrade
Version history
2.4.6latest on PyPI
Audit
Dependencies

No dependency data recorded yet.

Agent activity
63 hits · last 30 days
node
12
seranking-bot
4
ahrefsbot
2
Meta
1
bytedance
1
googlebot
1
Resources