scipy.special.exprel#
- scipy.special.exprel(x, out=None) = <ufunc 'exprel'>#
Relative error exponential,
(exp(x) - 1)/x
.When x is near zero,
exp(x)
is near 1, so the numerical calculation ofexp(x) - 1
can suffer from catastrophic loss of precision.exprel(x)
is implemented to avoid the loss of precision that occurs when x is near zero.- Parameters:
- xndarray
Input array. x must contain real numbers.
- outndarray, optional
Optional output array for the function values
- Returns:
- scalar or ndarray
(exp(x) - 1)/x
, computed element-wise.
See also
Notes
Added in version 0.17.0.
exprel
has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variableSCIPY_ARRAY_API=1
and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.Library
CPU
GPU
NumPy
✅
n/a
CuPy
n/a
✅
PyTorch
✅
⛔
JAX
⚠️ no JIT
⛔
Dask
✅
n/a
See Support for the array API standard for more information.
Examples
>>> import numpy as np >>> from scipy.special import exprel
>>> exprel(0.01) 1.0050167084168056 >>> exprel([-0.25, -0.1, 0, 0.1, 0.25]) array([ 0.88479687, 0.95162582, 1. , 1.05170918, 1.13610167])
Compare
exprel(5e-9)
to the naive calculation. The exact value is1.00000000250000000416...
.>>> exprel(5e-9) 1.0000000025
>>> (np.exp(5e-9) - 1)/5e-9 0.99999999392252903