scipy.special.powm1#
- scipy.special.powm1(x, y, out=None) = <ufunc 'powm1'>#
Computes
x**y - 1
.This function is useful when y is near 0, or when x is near 1.
The function is implemented for real types only (unlike
numpy.power
, which accepts complex inputs).- Parameters:
- xarray_like
The base. Must be a real type (i.e. integer or float, not complex).
- yarray_like
The exponent. Must be a real type (i.e. integer or float, not complex).
- Returns:
- array_like
Result of the calculation
Notes
New in version 1.10.0.
The underlying code is implemented for single precision and double precision floats only. Unlike
numpy.power
, integer inputs topowm1
are converted to floating point, and complex inputs are not accepted.Note the following edge cases:
powm1(x, 0)
returns 0 for anyx
, including 0,inf
andnan
.powm1(1, y)
returns 0 for anyy
, includingnan
andinf
.
Examples
>>> import numpy as np >>> from scipy.special import powm1
>>> x = np.array([1.2, 10.0, 0.9999999975]) >>> y = np.array([1e-9, 1e-11, 0.1875]) >>> powm1(x, y) array([ 1.82321557e-10, 2.30258509e-11, -4.68749998e-10])
It can be verified that the relative errors in those results are less than 2.5e-16.
Compare that to the result of
x**y - 1
, where the relative errors are all larger than 8e-8:>>> x**y - 1 array([ 1.82321491e-10, 2.30258035e-11, -4.68750039e-10])