scipy.special.exprel¶
- scipy.special.exprel(x) = <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.
- Returns
- float
(exp(x) - 1)/x
, computed element-wise.
See also
Notes
New in version 0.17.0.
Examples
>>> 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