pypi / numpy
numpy
What changed in numpy 2, from its official release notes, upgrade guides and advisories. Sources checked 2026-10-18.
76 breaking7 security19 deprecations26 new APIs and options8 performance17 behavior and defaults5 tooling71 fixes and other
See which of these apply to your code, ranked, in your agent:
npx @unstale/cli initnumpy 2229 changes
Breaking changes 76
When a copied fill_value cannot be represented in the new dtype, it resets to that dtype’s default; explicitly supplied fill_value values are still validated and raise as before.
Raises for inputs containing infinities instead of returning garbage results, and fixes hangs for certain such inputs with recent LAPACK implementations.
Raises for inputs containing infinities instead of returning garbage results, and fixes hangs for certain such inputs with recent LAPACK implementations.
Casting a fixed-width byte string array with invalid UTF-8 to StringDType now raises TypeError instead of storing invalid bytes.
The struct is opaque for extensions targeting the free-threading-compatible stable ABI, so those extensions can no longer access its fields; the NpyString allocator API remains usable with the descriptor pointer.
The minimum supported GCC version increased from 9.3.0 to 10.3.0, affecting developers building NumPy from source.
The data type alias 'a' has been removed; use 'S' instead.
_add_newdoc_ufunc(ufunc, newdoc) has been removed; assign ufunc.__doc__ instead.
Scalars now export the interface directly and are read-only, rather than exposing an array copy through a __ref entry.
Projects building against NumPy's Cython headers now require Cython 3.0 or newer.
get_array_wrap has been removed.
Windows platforms now require a minimum MSVC 19.35 toolchain, corresponding to Visual Studio 2022 version 17.5 Preview 2 or newer.
For object arrays, imag now returns getattr(element, "imag", 0) elementwise, and the result is read-only.
For object arrays, real now returns getattr(element, "real", element) elementwise, and the result is read-only.
This function has been removed.
Non-integer inputs now raise TypeError.
The re-export of numpy.char.chararray has been removed.
Two-dimensional vectors are no longer supported.
The function now accepts only numpy.ndarray; passing a scalar type raises TypeError.
Addition, subtraction, and integer multiplication now raise OverflowError when results overflow int64 or land on the NaT sentinel.
numpy.distutils has been removed.
Passing None as dtype now raises TypeError.
Unsupported device, dtype, or excessive dimensionality now raises BufferError instead of RuntimeError.
numpy.isreal is affected by the changed object-array imag behavior because it uses arr.imag.
The alias for the standard library math module has been removed.
numpy.linalg.eig now always returns complex arrays, rather than returning values whose type depended on the eigenvalues.
numpy.linalg.eigvals now always returns complex arrays, rather than returning values whose type depended on the eigenvalues.
meshgrid now always returns a tuple, including when sparse is true and copy is false.
Errors in the BTPE sampler's Stirling-series acceptance/rejection step were corrected, so results may differ for the same seed.
Results may differ for the same seed because the BTPE sampler used internally by multinomial had errors corrected.
numpy.row_stack has been removed in favor of numpy.vstack.
Addition, subtraction, and integer multiplication now raise OverflowError when results overflow int64 or land on the NaT sentinel.
Out-of-range Python integers in x or y are no longer silently truncated; they now raise OverflowError.
The C API function now raises OverflowError rather than silently truncating out-of-range Python integers.
NumPy 2.5.0 drops support for Python 3.11; supported Python versions are 3.12–3.14.
recfromtxt and recfromcsv have been removed from numpy.lib._npyio in favor of numpy.genfromtxt.
recfromtxt and recfromcsv have been removed from numpy.lib._npyio in favor of numpy.genfromtxt.
Copies of structured arrays with identical contiguous dtypes now use memcpy, which may copy padding bytes that were previously left untouched.
Returns rank 0 for empty matrices.
Converting an array with ndim greater than zero to a scalar now raises TypeError; extract a single element first.
The default x86 baseline has been raised to x86-64-v2; builds can set it to none to support older CPUs.
The deprecated, nonfunctional disp function has been removed.
Index preparation now matches ndarray behavior, with stricter validation, corrected IndexError types, and more specific errors; some float and scalar-boolean indices are deprecated.
Sorting with kind='heapsort' now maps to kind='quicksort', potentially changing execution time or unstable argsort order.
The deprecated runtime discovery mechanism has been removed.
The undocumented get_as_parameter method was removed; use _as_parameter_ instead.
The undocumented get_data method was removed; use data instead.
The undocumented get_shape method was removed; use shape instead.
The undocumented get_strides method was removed; use strides instead.
The macro defined in npy_cpu.h has been removed.
When used, NPY_HEAPSORT is mapped to NPY_QUICKSORT.
Deleting numpy from sys.modules and importing it again now fails with ImportError because C extension modules are checked for single import per process.
Type checkers no longer accept start as a keyword argument, though runtime use remains possible.
The style parameter has been removed; arguments following it, such as formatter, are now keyword-only.
The bias argument has been removed because it had no effect.
The ddof argument has been removed because it had no effect.
The deprecated module has been removed; use numpy.fft instead.
Removed in favor of numpy.isin.
The deprecated module has been removed; use numpy.linalg instead.
The delimitor parameter has been removed; use delimiter instead.
The interpolation parameter has been removed; use method instead.
The interpolation parameter has been removed; use method instead.
Removed; use next(ndindex) instead.
The interpolation parameter has been removed; use method instead.
The interpolation parameter has been removed; use method instead.
The newshape parameter has been removed; pass the shape positionally or use shape= on newer NumPy versions.
Always returns a copy, including for integer inputs with nonnegative decimals.
The ignored fix_imports parameter has been removed.
Passing a generator directly now raises TypeError; use numpy.fromiter or Python's sum builtin.
Removed; use numpy.trapezoid or scipy.integrate functions instead.
The type alias no longer accepts None; use DTypeLike | None for optional dtype annotations.
Hash-based unique extraction speeds up string arrays substantially, but returned unique values are not guaranteed to be sorted.
Multiplication that would create an unrepresentably large string now raises OverflowError instead of MemoryError.
New x86 CPU feature group representing x86-64-v3 microarchitectures.
New x86 CPU feature group representing x86-64-v4 microarchitectures.
Negative input now raises ValueError.
Security 7
Setting an array's dtype attribute is deprecated because mutating a shared array is unsafe; use array.view(dtype=new_dtype).
Resizing an array in place is deprecated because mutating a shared array is unsafe; use np.resize instead.
Fixes a heap buffer overflow in timedelta-to-string casts.
Fixes a heap overflow in fixed-width string multiplication.
Setting the strides attribute is deprecated because mutating a shared array is unsafe; create a new view instead.
Setting an array's shape attribute is deprecated; use np.reshape or np.ndarray.reshape to create a new view.
Avoids a segmentation fault in string_expandtabs_length_promoter.
Deprecations 19
The numpy.char.array and numpy.char.asarray functions are deprecated; use numpy.array or numpy.asarray with a string or bytes dtype.
This class is deprecated; use an ndarray with a string or bytes dtype instead.
numpy.ma.round_ is deprecated; use numpy.ma.round instead.
The same-kind cast check now tests whether the result can be cast to out; a DeprecationWarning is issued when it cannot.
Using the generic unit is deprecated, as are operations that implicitly rely on it; specify an explicit unit instead.
Non-integer values for M, k, and N are deprecated.
Non-integer values for k are deprecated.
Inputs other than integers are deprecated.
Non-integer values for k are deprecated.
Inputs other than integers are deprecated.
numpy.typename is deprecated because its returned names were outdated and inconsistent; use numpy.dtype.name instead.
A VisibleDeprecationWarning is emitted when align is not a boolean; pass align as a keyword argument.
numpy.fix is deprecated; use numpy.trunc, which provides identical functionality and follows the Array API standard.
The container class is deprecated and will be removed in a future version.
Passing out positionally is deprecated; pass it by keyword to distinguish the output buffer from inputs.
Passing out positionally is deprecated; pass it by keyword to distinguish the output buffer from inputs.
Deprecated in favor of warnings.catch_warnings, warnings.filterwarnings, pytest.warns, or pytest.filterwarnings.
Deprecated in favor of warnings.catch_warnings, warnings.filterwarnings, pytest.warns, or pytest.filterwarnings.
Calling a ufunc with where but without out now emits a warning; out=None suppresses it.
New APIs and options 26
A new polynomial function evaluates polynomials in arbitrary dimensions.
A new polynomial function evaluates polynomials in arbitrary dimensions.
A new polynomial function evaluates polynomials in arbitrary dimensions.
A new polynomial function evaluates polynomials in arbitrary dimensions.
A new polynomial function evaluates polynomials in arbitrary dimensions.
The descending keyword enables descending argsorts; NaNs remain at the end, and the feature supports built-in dtypes except void, object, and generic.
User-dtype authors can register dtypes for DLPack export and import.
The descending keyword enables descending sorts; NaNs remain at the end, and the feature supports built-in dtypes except void, object, and generic.
A new polynomial function evaluates polynomials in arbitrary dimensions.
A new C API accessor macro allows accessing a PyArray_Descr field without direct field access.
A new C API accessor macro allows accessing a PyArray_Descr field without direct field access.
A new C API accessor macro allows accessing a PyArray_Descr field without direct field access.
A new C API accessor macro allows accessing a PyArray_Descr field without direct field access.
User-defined dtypes can implement custom sorting and argsorting with ArrayMethod specs registered through PyUFunc_AddLoopsFromSpecs.
The same_value casting option verifies that values round-trip without changing; it raises ValueError if casting changes any value.
New DType API slot lets dtype implementations provide constants such as machine limits and special values, enabling numpy.finfo support.
New NPY_SORTKIND enum name for default sorting, with the same value as NPY_QUICKSORT.
New NPY_SORTKIND enum name for descending sort; it is not yet implemented.
New NPY_SORTKIND enum name indicating that sorting must be stable.
NumPy checks this protocol when converting objects to dtypes through np.dtype or dtype arguments, allowing dtype-like objects to define conversion explicitly.
The ndmax option limits the maximum dimensions created from nested sequences, useful for preserving nested structures as object elements.
The pad_width argument now accepts a dictionary.
Accepts multiple axes.
The axis argument now accepts a sequence to trim zeros along multiple axes.
New C API function registers multiple ufunc loops from specs in one call, including sorting and argsorting loops using ArrayMethod.
New x86 CPU feature group representing x86-64-v2 microarchitectures.
Performance 8
Reductions over all axes now use a fast path for contiguous, aligned, non-object arrays with no special arguments.
Reductions over all axes now use a fast path for contiguous, aligned, non-object arrays with no special arguments.
Reductions over all axes now use a fast path for contiguous, aligned, non-object arrays with no special arguments.
Searching for multiple keys is substantially faster through batched binary search steps; single-key performance remains comparable.
Reductions over all axes now use a fast path for contiguous, aligned, non-object arrays with no special arguments.
Ufuncs scale significantly better on free-threading CPython builds through lock-free dispatch, immortal shared objects, and optimized memory allocation.
Iteration over large iteration spaces is significantly faster while preserving the original behavior and interface.
Single-input ufunc calculations on scalars are about six times faster; array performance is unchanged.
Behavior and default changes 17
NumPy now uses PyMem_RawMalloc and PyMem_RawFree instead of the system malloc and free; internal allocations can be tracked by tracemalloc.
When dtype or order correction is needed, f2py now keeps a separate corrected array and copies it back after the Fortran call; only equivalent dtype kinds are allowed.
FFT functions now support non-float64 and non-complex128 dtypes and gain preliminary shape-typing support.
Input and output dtypes are more precise, and several functions gain preliminary, backward-compatible shape-typing support.
ndarray and its subclasses now support structural pattern matching with match/case statements.
The function now returns the full dtype descriptor, including parameters, for scalars of user-defined parametric data types.
This C API can now register real and imag ArrayMethods for use by imag and real.
Subclasses with dtype-specific logic should set _set_dtype to None to have arr.view(dtype=new_dtype) call __array_finalize__ with the new dtype, or define a function calling ndarray._set_dtype().
NumPy now supports the stable ABI for free-threaded Python.
Typing now accepts NumPy scalars and arrays as the second argument.
Accepts datetime strings.
The default parameter can accept array-like values.
The array interface accepts NULL data pointers and performs a dummy allocation; omit the data field to use the previous scalar path.
Assertion failure messages now include the indices at which the comparison fails.
The repr of NaT values now includes the datetime64 time unit.
Masked arrays accept and preserve Python strings as fill_value with variable-width StringDType, including through slicing and views; the default is N/A.
Hash-based unique extraction now supports complex dtypes and can return unsorted results.
Tooling 5
The module now has typing annotations across masked arrays, masks, functions, and methods.
Many functions and methods now have shape-aware return annotations, allowing type-checkers to infer result array dimensions for common operations.
On win-arm64, the library file extension is now .lib instead of .a for MSVC and setuptools compatibility.
On win-arm64, the library file extension is now .lib instead of .a for MSVC and setuptools compatibility.
On win-arm64, the npymath and npyrandom static libraries now use the .lib extension instead of .a for compatibility with MSVC and setuptools.
Fixes and other changes 71
Includes a workaround for an MSVC 19.51 bug.
Fixes truncation of the old and new strings to the length of the input array’s string.
Handles non-finite inputs more consistently.
Instances with equivalent floating-point NaN sentinels now have equal hashes, so dictionary lookups and set deduplication no longer fail because equal dtypes had different hashes.
Includes many typing fixes and improvements.
Fixes two possible crashes in the accumulate implementation.
When a dtype-changing ufunc leaves the copied fill_value invalid for the new dtype, NumPy now uses that dtype’s default fill_value instead of propagating a stale value.
Fixes the stride after removing a multi-index.
Fixes cast errors being swallowed during assignment.
Restores conjugate behavior for legacy user-defined dtypes.
Fixes a reference-count leak for overlapping copies when where is False.
Fixes corruption when reusing a StringDType.
Adds a special case for StringDType.
The release supports Python 3.15 and includes wheels for Python 3.15.0rc1.
Ensures the lock is held when accessing or writing RNG state and fully resets cached state for non-MT19937 RNGs.
Fixes the coerce flag in binary ufunc promotion.
Fixed an output-array leak in accumulate when dtype …
Corrected dtype inference for asarray([]).
The datetime Cython APIs were fixed to be compatible with older NumPy versions, helping downstream projects support those versions.
finfo is more accessible for user-defined dtypes.
Corrected the return type for object_ values.
Fixed a segfault by preventing recursive seed lists.
Fixed a typing regression introduced in NumPy 2.5.0.
Deadlocks when using the NpyString API were fixed.
Fixed an output-array leak in reduceat when dtype …
Fixed a leak in reductions when a ufunc override errors or is …
Fixed several bugs in StringDType operations.
Allocatable module variables wrapped by f2py now appear in dir() output.
numpy.triu_indices now accepts unsigned integers in all cases.
StringDType comparisons now correctly handle embedded NULL bytes.
Fixes a regression in arr.conj().
Fixes non-unitary results from np.linalg.svd(..., hermitian=True).
Fixes support for runtime type checkers.
Maps complex_long_double to NPY_CLONGDOUBLE.
Fixes typing for boolean and non-1D inputs.
Fixes in-place aliasing when out is the input.
Fixes a segfault when __getitem__ raises.
Undo the deprecation of the signature used by old pickles.
Fixes failures with a 0-dimensional out argument.
Fixes the assignability of np.shape for Python lists.
Fixes a memory leak when the fill-zero loop raises.
Prevents a deadlock caused by downstream code importing NumPy during dlopen.
Fixes typing for the axis parameter.
Fixes incorrect temporary elision for new-style user-defined dtypes.
Fixes in-place aliasing when out is the input.
Fixes 64-bit selection by using NPY_SIZEOF_UINTP.
Avoids a warning when a ufunc is called with where=True and no output.
Fixes handling of a bool array weekmask.
Fixes a weak hash function used by np.isin().
Fixes infinite recursion in np.ma.flatten_structured_array.
Adds missing extended precision imports to matlib's typing support.
Fixes the OpenBLAS threading problem on ARM.
Fixes memory leaks discovered after the 2.4.1 release.
Updates OpenBLAS to fix hangs.
Fixes the quantile promotion fixup.
Fixes validation of contraction axes.
Fixes a leak in the flat assignment iterator.
Fixes the return type of histogram2d.
Preserves the SeedlessSequence typo so wheels using the random Cython API and built against NumPy < 2.4.0 run without errors.
Many NumPy functions, classes, and methods now return meaningful signatures instead of raising ValueError, improving introspection and tooling support.
Accuracy is improved for 16- and 32-bit floating-point input data.
Accuracy is improved for 16- and 32-bit floating-point input data.
This release supports Python versions 3.11–3.14.
Fixed resize when the array contains references.
Fixed the implementation to avoid negating INT_MIN.
Fixed float16-sort failures on 32-bit x86 MSVC.
Fixed an assertion failure in buffer setup.
A malloc failure now emits MemoryError.
Fixed umath strides for AIX compatibility.
INT_MIN % -1 now returns 0 for all signed integer types.
Fixed negative samples generated by the Wald distribution.