many new features, numerous bug-fixes, improved test coverage and better
documentation. There have been a number of deprecations and API changes
in this release, which are documented below. All users are encouraged to
upgrade to this release, as there are a large number of bug-fixes and
optimizations. Before upgrading, we recommend that users check that
their own code does not use deprecated SciPy functionality (to do so,
run your code with ``python -Wd`` and check for ``DeprecationWarning`` s).
Our development attention will now shift to bug-fix releases on the
1.15.x branch, and on adding new features on the main branch.
This release requires Python `3.10-3.13` and NumPy `1.23.5` or greater.
Highlights of this release
===================
- Sparse arrays are now fully functional for 1-D and 2-D arrays. We recommend
that all new code use sparse arrays instead of sparse matrices and that
developers start to migrate their existing code from sparse matrix to sparse
array: [ `migration_to_sparray`](https://scipy.github.io/devdocs/reference/sparse.migration_to_sparray.html). Both ``sparse.linalg`` and ``sparse.csgraph``
work with either sparse matrix or sparse array and work internally with
sparse array.
- Sparse arrays now provide basic support for n-D arrays in the COO format
including ``add``, ``subtract``, ``reshape``, ``transpose``, ``matmul``,
``dot``, ``tensordot`` and others. More functionality is coming in future
releases.
- Preliminary support for free-threaded Python 3.13.
- New probability distribution features in `scipy.stats` can be used to improve
the speed and accuracy of existing continuous distributions and perform new
probability calculations.
- `scipy.differentiate` is a new top-level submodule for accurate
estimation of derivatives of black box functions.
- `scipy.optimize.elementwise` provides vectorized root-finding and
minimization of univariate functions, and it supports the array API
as do new ``integrate`` functions ``tanhsinh``, ``nsum``, and ``cubature``.
- `scipy.interpolate.AAA` adds the AAA algorithm for barycentric rational
approximation of real or complex functions.
New features
==========
`scipy.differentiate` introduction
=========================
The new `scipy.differentiate` sub-package contains functions for accurate
estimation of derivatives of black box functions.
* Use `scipy.differentiate.derivative` for first-order derivatives of
scalar-in, scalar-out functions.
* Use `scipy.differentiate.jacobian` for first-order partial derivatives of
vector-in, vector-out functions.
* Use `scipy.differentiate.hessian` for second-order partial derivatives of
vector-in, scalar-out functions.
All functions use high-order finite difference rules with adaptive (real)
step size. To facilitate batch computation, these functions are vectorized
and support several Array API compatible array libraries in addition to NumPy
(see "Array API Standard Support" below).
`scipy.integrate` improvements
========================
- The ``QUADPACK`` Fortran77 package has been ported to C.
- `scipy.integrate.lebedev_rule` computes abscissae and weights for
integration over the surface of a sphere.
- `scipy.integrate.nsum` evaluates finite and infinite series and their
logarithms.
- `scipy.integrate.tanhsinh` is now exposed for public use, allowing
evaluation of a convergent integral using tanh-sinh quadrature.
- The new `scipy.integrate.cubature` function supports multidimensional
integration, and has support for approximating integrals with
one or more sets of infinite limits.
`scipy.interpolate` improvements
===========================
- `scipy.interpolate.AAA` adds the AAA algorithm for barycentric rational
approximation of real or complex functions.
- `scipy.interpolate.FloaterHormannInterpolator` adds barycentric rational
interpolation.
- New functions `scipy.interpolate.make_splrep` and
`scipy.interpolate.make_splprep` implement construction of smoothing splines.
The algorithmic content is equivalent to FITPACK (``splrep`` and ``splprep``
functions, and ``*UnivariateSpline`` classes) and the user API is consistent
with ``make_interp_spline``: these functions receive data arrays and return
a `scipy.interpolate.BSpline` instance.
- New generator function `scipy.interpolate.generate_knots` implements the
FITPACK strategy for selecting knots of a smoothing spline given the
smoothness parameter, ``s``. The function exposes the internal logic of knot
selection that ``splrep`` and ``*UnivariateSpline`` was using.
`scipy.linalg` improvements
======================
- `scipy.linalg.interpolative` Fortran77 code has been ported to Cython.
- `scipy.linalg.solve` supports several new values for the ``assume_a``
argument, enabling faster computation for diagonal, tri-diagonal, banded, and
triangular matrices. Also, when ``assume_a`` is left unspecified, the
function now automatically detects and exploits diagonal, tri-diagonal,
and triangular structures.
- `scipy.linalg` matrix creation functions (`scipy.linalg.circulant`,
`scipy.linalg.companion`, `scipy.linalg.convolution_matrix`,
`scipy.linalg.fiedler`, `scipy.linalg.fiedler_companion`, and
`scipy.linalg.leslie`) now support batch
matrix creation.
- `scipy.linalg.funm` is faster.
- `scipy.linalg.orthogonal_procrustes` now supports complex input.
- Wrappers for the following LAPACK routines have been added in
`scipy.linalg.lapack`: ``?lantr``, ``?sytrs``, ``?hetrs``, ``?trcon``,
and ``?gtcon``.
- `scipy.linalg.expm` was rewritten in C.
- `scipy.linalg.null_space` now accepts the new arguments ``overwrite_a``,
``check_finite``, and ``lapack_driver``.
- ``id_dist`` Fortran code was rewritten in Cython.
`scipy.ndimage` improvements
========================
- Several additional filtering functions now support an ``axes`` argument
that specifies which axes of the input filtering is to be performed on.
These include ``correlate``, ``convolve``, ``generic_laplace``, ``laplace``,
``gaussian_laplace``, ``derivative2``, ``generic_gradient_magnitude``,
``gaussian_gradient_magnitude`` and ``generic_filter``.
- The binary and grayscale morphology functions now support an ``axes``
argument that specifies which axes of the input filtering is to be performed
on.
- `scipy.ndimage.rank_filter` time complexity has improved from ``n`` to
``log(n)``.
`scipy.optimize` improvements
========================
- The vendored HiGHS library has been upgraded from ``1.4.0`` to ``1.8.0``,
bringing accuracy and performance improvements to solvers.
- The ``MINPACK`` Fortran77 package has been ported to C.
- The ``L-BFGS-B`` Fortran77 package has been ported to C.
- The new `scipy.optimize.elementwise` namespace includes functions
``bracket_root``, ``find_root``, ``bracket_minimum``, and ``find_minimum``
for root-finding and minimization of univariate functions. To facilitate
batch computation, these functions are vectorized and support several
Array API compatible array libraries in addition to NumPy (see
"Array API Standard Support" below). Compared to existing functions (e.g.
`scipy.optimize.root_scalar` and `scipy.optimize.minimize_scalar`),
these functions can offer speedups of over 100x when used with NumPy arrays,
and even greater gains are possible with other Array API Standard compatible
array libraries (e.g. CuPy).
- `scipy.optimize.differential_evolution` now supports more general use of
``workers``, such as passing a map-like callable.
- `scipy.optimize.nnls` was rewritten in Cython.
- ``HessianUpdateStrategy`` now supports ``__matmul__``.
`scipy.signal` improvements
======================
- Add functionality of complex-valued waveforms to ``signal.chirp()``.
- `scipy.signal.lombscargle` has two new arguments, ``weights`` and
``floating_mean``, enabling sample weighting and removal of an unknown
y-offset independently for each frequency. Additionally, the ``normalize``
argument includes a new option to return the complex representation of the
amplitude and phase.
- New function `scipy.signal.envelope` for computation of the envelope of a
real or complex valued signal.
`scipy.sparse` improvements
=======================
- A :ref:`migration guide<migration_to_sparray>` is now available for
moving from sparse.matrix to sparse.array in your code/library.
- Sparse arrays now support indexing for 1-D and 2-D arrays. So, sparse
arrays are now fully functional for 1-D and 2D.
- n-D sparse arrays in COO format can now be constructed, reshaped and used
for basic arithmetic.
- New functions ``sparse.linalg.is_sptriangular`` and
``sparse.linalg.spbandwidth`` mimic the existing dense tools
``linalg.is_triangular`` and ``linalg.bandwidth``.
- ``sparse.linalg`` and ``sparse.csgraph`` now work with sparse arrays. Be
careful that your index arrays are 32-bit. We are working on 64bit support.
- The vendored ``ARPACK`` library has been upgraded to version ``3.9.1``.
- COO, CSR, CSC and LIL formats now support the ``axis`` argument for
``count_nonzero``.
- Sparse arrays and matrices may now raise errors when initialized with
incompatible data types, such as ``float16``.
- ``min``, ``max``, ``argmin``, and ``argmax`` now support computation
over nonzero elements only via the new ``explicit`` argument.
- New functions ``get_index_dtype`` and ``safely_cast_index_arrays`` are
available to facilitate index array casting in ``sparse``.
`scipy.spatial` improvements
======================
- ``Rotation.concatenate`` now accepts a bare ``Rotation`` object, and will
return a copy of it.
`scipy.special` improvements
========================
- The factorial functions ``special.{factorial,factorial2,factorialk}`` now
offer an extension to the complex domain by passing the kwarg
``extend='complex'``. This is opt-in because it changes the values for
negative inputs (which by default return 0), as well as for some integers
(in the case of ``factorial2`` and ``factorialk``; for more details,
check the respective docstrings).
- `scipy.special.zeta` now defines the Riemann zeta function on the complex
plane.
- `scipy.special.softplus` computes the softplus function
- The spherical Bessel functions (`scipy.special.spherical_jn`,
`scipy.special.spherical_yn`, `scipy.special.spherical_in`, and
`scipy.special.spherical_kn`) now support negative arguments with real dtype.
- `scipy.special.logsumexp` now preserves precision when one element of the
sum has magnitude much bigger than the rest.
- The accuracy of several functions has been improved:
- `scipy.special.ncfdtr` and `scipy.special.nctdtr` have been improved
throughout the domain.
- `scipy.special.hyperu` is improved for the case of ``b=1``, small ``x``,
and small ``a``.
- `scipy.special.logit` is improved near the argument ``p=0.5``.
- `scipy.special.rel_entr` is improved when ``x/y`` overflows, underflows,
or is close to ``1``.
- `scipy.special.gdtrib` may now be used in a CuPy ``ElementwiseKernel`` on
GPUs.
- `scipy.special.ndtr` is now more efficient.
`scipy.stats` improvements
=====================
- A new probability distribution infrastructure has been added for the
implementation of univariate, continuous distributions with speed,
accuracy, and memory advantages:
- `scipy.stats.Normal` represents the normal distribution with the new
interface. In typical cases, its methods are faster and more accurate than
those of `scipy.stats.norm`.
- Use `scipy.stats.make_distribution` to treat an existing continuous
distribution (e.g. `scipy.stats.norm`) with the new infrastructure.
This can improve the speed and accuracy of existing distributions,
especially for methods not overridden with custom formulas in the
implementation.
- `scipy.stats.Mixture` has been added to represent mixture distributions.
- Instances of `scipy.stats.Normal` and the classes returned by
`scipy.stats.make_distribution` are supported by several new mathematical
transformations.
- `scipy.stats.truncate` for truncation of the support.
- `scipy.stats.order_statistic` for the order statistics of a given number
of IID random variables.
- `scipy.stats.abs`, `scipy.stats.exp`, and `scipy.stats.log`. For example,
``scipy.stats.abs(Normal())`` is distributed according to the folded normal
and ``scipy.stats.exp(Normal())`` is lognormally distributed.
- The new `scipy.stats.lmoment` calculates sample l-moments and l-moment
ratios. Notably, these sample estimators are unbiased.
- `scipy.stats.chatterjeexi` computes the Xi correlation coefficient, which
can detect nonlinear dependence. The function also performs a hypothesis
test of independence between samples.
- `scipy.stats.wilcoxon` has improved method resolution logic for the default
``method='auto'``. Other values of ``method`` provided by the user are now
respected in all cases, and the method argument ``approx`` has been
renamed to ``asymptotic`` for consistency with similar functions. (Use of
``approx`` is still allowed for backward compatibility.)
- There are several new probability distributions:
- `scipy.stats.dpareto_lognorm` represents the double Pareto lognormal
distribution.
- `scipy.stats.landau` represents the Landau distribution.
- `scipy.stats.normal_inverse_gamma` represents the normal-inverse-gamma
distribution.
- `scipy.stats.poisson_binom` represents the Poisson binomial distribution.
- Batch calculation with `scipy.stats.alexandergovern` and
`scipy.stats.combine_pvalues` is faster.
- `scipy.stats.chisquare` added an argument ``sum_check``. By default, the
function raises an error when the sum of expected and obseved frequencies
are not equal; setting ``sum_check=False`` disables this check to
facilitate hypothesis tests other than Pearson's chi-squared test.
- The accuracy of several distribution methods has been improved, including:
- `scipy.stats.nct` method ``pdf``
- `scipy.stats.crystalball` method ``sf``
- `scipy.stats.geom` method ``rvs``
- `scipy.stats.cauchy` methods ``logpdf``, ``pdf``, ``ppf`` and ``isf``
- The ``logcdf`` and/or ``logsf`` methods of distributions that do not
override the generic implementation of these methods, including
`scipy.stats.beta`, `scipy.stats.betaprime`, `scipy.stats.cauchy`,
`scipy.stats.chi`, `scipy.stats.chi2`, `scipy.stats.exponweib`,
`scipy.stats.gamma`, `scipy.stats.gompertz`, `scipy.stats.halflogistic`,
`scipy.stats.hypsecant`, `scipy.stats.invgamma`, `scipy.stats.laplace`,
`scipy.stats.levy`, `scipy.stats.loggamma`, `scipy.stats.maxwell`,
`scipy.stats.nakagami`, and `scipy.stats.t`.
- `scipy.stats.qmc.PoissonDisk` now accepts lower and upper bounds
parameters ``l_bounds`` and ``u_bounds``.
- `scipy.stats.fisher_exact` now supports two-dimensional tables with shapes
other than ``(2, 2)``.
Preliminary Support for Free-Threaded CPython 3.13
========================================