scipy.special.cosm1#
- scipy.special.cosm1(x, out=None) = <ufunc 'cosm1'>#
Compute
cos(x) - 1, especially when x is near zero.- Parameters:
- xarray_like
Real valued argument.
- outndarray, optional
Optional output array for the function results.
- Returns:
- scalar or ndarray
Values of
cos(x) - 1.
Notes
Array API Standard Support
cosm1has 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 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.cosm1does not currently supportoutfor the PyTorch backend.See Support for the array API standard for more information.
Examples
>>> import numpy as np >>> import scipy.special as sc
It is more accurate than computing
cos(x) - 1directly forxaround 0.>>> x = 1e-30 >>> np.cos(x) - 1 0.0 >>> sc.cosm1(x) -5.0000000000000005e-61