scipy.special.powm1#

scipy.special.powm1(x, y, out=None) = <wrapped_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

Added in version 1.10.0.

The underlying code is implemented for single precision and double precision floats only. Unlike numpy.power, integer inputs to powm1 are converted to floating point, and complex inputs are not accepted.

Note the following edge cases:

  • powm1(x, 0) returns 0 for any x, including 0, inf and nan.

  • powm1(1, y) returns 0 for any y, including nan and inf.

This function wraps the powm1 routine from the Boost Math C++ library [1].

Array API Standard Support

powm1 has 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. out is 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. out is never supported for JAX because JAX arrays are immutable. powm1 does not currently support out for the PyTorch backend.

See Array API coverage for more information.

References

[1]

The Boost Developers. “Boost C++ Libraries”. https://www.boost.org/.

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])