scipy.special.expm1#
- scipy.special.expm1(x, out=None) = <wrapped_ufunc 'expm1'>#
Compute
exp(x) - 1.When x is near zero,
exp(x)is near 1, so the numerical calculation ofexp(x) - 1can suffer from catastrophic loss of precision.expm1(x)is implemented to avoid the loss of precision that occurs when x is near zero.- Parameters:
- xarray_like
x must contain real numbers.
- outndarray, optional
Optional output array for the function values
- Returns:
- scalar or ndarray
exp(x) - 1computed element-wise.
Notes
Array API Standard Support
expm1has support for Python Array API Standard compatible backends in addition to NumPy. The following combinations of backend and device (or other capability) are supported.Library
CPU
GPU
NumPy
✅
n/a
CuPy
n/a
✅
PyTorch
✅
⛔
JAX
✅
⛔
Dask
✅
n/a
For the NumPy backend, this function supports all NumPy ufunc keyword arguments. Other backends may support
out, but typically none of the other ufunc kwargs.outis typically supported for CuPy and PyTorch, but not currently in cases where SciPy relies on a generic Array API implementation or, for PyTorch on CPU, falls back to the NumPy backend.outis never supported for JAX because JAX arrays are immutable.expm1does not currently supportoutfor the PyTorch backend.See Array API coverage for more information.
Examples
>>> import numpy as np >>> from scipy.special import expm1
>>> expm1(1.0) 1.7182818284590451 >>> expm1([-0.2, -0.1, 0, 0.1, 0.2]) array([-0.18126925, -0.09516258, 0. , 0.10517092, 0.22140276])
The exact value of
exp(7.5e-13) - 1is:7.5000000000028125000000007031250000001318...*10**-13.
Here is what
expm1(7.5e-13)gives:>>> expm1(7.5e-13) 7.5000000000028135e-13
Compare that to
exp(7.5e-13) - 1, where the subtraction results in a “catastrophic” loss of precision:>>> np.exp(7.5e-13) - 1 7.5006667543675576e-13