scipy.special.boxcox#
- scipy.special.boxcox(x, lmbda, out=None) = <ufunc 'boxcox'>#
Compute the Box-Cox transformation.
The Box-Cox transformation is
\[\begin{split}y = \begin{cases} (x^\lambda - 1) / \lambda & \text{if } \lambda \neq 0 \\ \log(x) & \text{if } \lambda = 0 \end{cases}\end{split}\]Returns
nanif \(x < 0\). Returns-infif \(x = 0\) and \(\lambda \leq 0\).- Parameters:
- xarray_like
Data to be transformed.
- lmbdaarray_like
Power parameter \(\lambda\) of the Box-Cox transform.
- outndarray, optional
Optional output array for the function values.
- Returns:
- yscalar or ndarray
Transformed data.
See also
boxcox1pBox-Cox transformation of
1 + x.inv_boxcoxInverse of the Box-Cox transformation.
Notes
Added in version 0.14.0.
Array API Standard Support
boxcoxhas 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.boxcoxdoes not currently supportoutfor the PyTorch backend.See Support for the array API standard for more information.
Examples
>>> from scipy.special import boxcox >>> boxcox([1, 4, 10], 2.5) array([ 0. , 12.4 , 126.09110641]) >>> boxcox(2, [0, 1, 2]) array([ 0.69314718, 1. , 1.5 ])