NumPy 2.0.0 Release Notes#
NumPy 2.0 Python API removals#
Alias
np.float_
has been removed. Usenp.float64
instead.Alias
np.complex_
has been removed. Usenp.complex128
instead.Alias
np.longfloat
has been removed. Usenp.longdouble
instead.Alias
np.singlecomplex
has been removed. Usenp.complex64
instead.Alias
np.cfloat
has been removed. Usenp.complex128
instead.Alias
np.longcomplex
has been removed. Usenp.clongdouble
instead.Alias
np.clongfloat
has been removed. Usenp.clongdouble
instead.Alias
np.string_
has been removed. Usenp.bytes_
instead.Alias
np.unicode_
has been removed. Usenp.str_
instead.Alias
np.Inf
has been removed. Usenp.inf
instead.Alias
np.Infinity
has been removed. Usenp.inf
instead.Alias
np.NaN
has been removed. Usenp.nan
instead.Alias
np.infty
has been removed. Usenp.inf
instead.Alias
np.mat
has been removed. Usenp.asmatrix
instead.np.issubclass_
has been removed. Useissubclass
builtin instead.np.asfarray
has been removed. Usenp.asarray
with a proper dtype instead.np.set_string_function
has been removed. Usenp.set_printoptions
instead with a formatter for custom printing of NumPy objects.np.tracemalloc_domain
is now only available fromnp.lib
.np.recfromcsv
andrecfromtxt
are now only available fromnp.lib.npyio
.np.issctype
,np.maximum_sctype
,np.obj2sctype
,np.sctype2char
,np.sctypeDict
,np.sctypes
,np.issubsctype
were all removed from the main namespace without replacement, as they where niche members.Deprecated
np.deprecate
andnp.deprecate_with_doc
has been removed from the main namespace. UseDeprecationWarning
instead.Deprecated
np.safe_eval
has been removed from the main namespace. Useast.literal_eval
instead.(gh-24376)
np.find_common_type
has been removed. Usenumpy.promote_types
ornumpy.result_type
instead. To achieve semantics for thescalar_types
argument, usenumpy.result_type
and pass the Pythonvalues0
,0.0
, or0j
.np.round_
has been removed. Usenp.round
instead.np.nbytes
has been removed. Usenp.dtype(<dtype>).itemsize
instead.(gh-24477)
np.compare_chararrays
has been removed from the main namespace. Usenp.char.compare_chararrays
instead.The
charrarray
in the main namespace has been deprecated. It can be imported without a deprecation warning fromnp.char.chararray
for now, but we are planning to fully deprecate and removechararray
in the future.np.format_parser
has been removed from the main namespace. Usenp.rec.format_parser
instead.(gh-24587)
Deprecations#
np.trapz
has been deprecated. Usescipy.interpolate.trapezoid
instead.np.in1d
has been deprecated. Usenp.isin
instead.Alias
np.row_stack
has been deprecated. Usenp.vstack
directly.(gh-24445)
New Features#
np.bitwise_count to compute the number of 1-bits in an integer array#
This new function counts the number of 1-bits in a number. np.bitwise_count works on all the numpy integer types and integer-like objects.
>>> a = np.array([2**i - 1 for i in range(16)])
>>> np.bitwise_count(a)
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
dtype=uint8)
(gh-19355)
Support for the updated Accelerate BLAS/LAPACK library, including ILP64 (64-bit integer) support, in macOS 13.3 has been added. This brings arm64 support, and significant performance improvements of up to 10x for commonly used linear algebra operations. When Accelerate is selected at build time, the 13.3+ version will automatically be used if available.
(gh-24053)
Improved CPU Optimization Tracking#
Introduces a tracer mechanism that enables tracking of the enabled targets for each optimized function in the NumPy library. With this enhancement, it becomes possible to precisely monitor the enabled CPU dispatch targets for the dispatched functions.
A new function named opt_func_info has been added to the new namespace numpy.lib.introspect
,
offering this tracing capability. This function allows you to retrieve information
about the enabled targets based on function names and data type signatures.
(gh-24420)
meson
backend for f2py
#
f2py
in compile mode (i.e. f2py -c
) now accepts the --backend meson
option. This is the default option
for Python 3.12
on-wards. Older versions will still default to --backend
distutils
.
To support this in realistic use-cases, in compile mode f2py
takes a
--dep
flag one or many times which maps to dependency()
calls in the
meson
backend, and does nothing in the distutils
backend.
There are no changes for users of f2py
only as a code generator, i.e. without -c
.
(gh-24532)
bind(c)
support for f2py
#
Both functions and subroutines can be annotated with bind(c)
. f2py
will
handle both the correct type mapping, and preserve the unique label for other
C
interfaces.
- Note:
bind(c, name = 'routine_name_other_than_fortran_routine')
is not honored by the
f2py
bindings by design, sincebind(c)
with thename
is meant to guarantee only the same name inC
andFortran
, not inPython
andFortran
.
(gh-24555)
strict
option for testing.assert_allclose#
The strict
option is now available for testing.assert_allclose.
Setting strict=True
will disable the broadcasting behaviour for scalars
and ensure that input arrays have the same data type.
(gh-24680)
Improvements#
iso_c_binding
support for f2py
#
Previously, users would have to define their own custom f2cmap
file to use
type mappings defined by the Fortran2003 iso_c_binding
intrinsic module.
These type maps are now natively supported by f2py
(gh-24555)
Changes#
np.lib.array_utils
public module has been introduced and in its initial version it hosts three functions:byte_bounds
(moved fromnp.lib.utils
),normalize_axis_tuple
andnormalize_axis_index
(gh-24540)
The “relaxed strides” debug build option, which was previously enabled through
the NPY_RELAXED_STRIDES_DEBUG
environment variable or the
-Drelaxed-strides-debug
config-settings flag, has been removed.
(gh-24717)