PPoly#
- class scipy.interpolate.PPoly(c, x, extrapolate=None, axis=0)[source]#
Piecewise polynomial in the power basis.
The polynomial between
x[i]andx[i + 1]is written in the local power basis:S = sum(c[m, i] * (xp - x[i])**(k-m) for m in range(k+1))
where
kis the degree of the polynomial.- Parameters:
- cndarray, shape (k+1, m, …)
Polynomial coefficients, degree k and m intervals.
- xndarray, shape (m+1,)
Polynomial breakpoints. Must be sorted in either increasing or decreasing order.
- extrapolate{bool, ‘periodic’, None}, optional
If bool, determines whether to extrapolate to out-of-bounds points based on first and last intervals, or to return NaNs. If ‘periodic’, periodic extrapolation is used. If None (default), it is set to True. See Out-of-bounds behavior.
- axisint, optional
Interpolation axis. Default is zero.
- Attributes:
- xndarray
Breakpoints.
- cndarray
Coefficients of the polynomials. They are reshaped to a 3-D array with the last dimension representing the trailing dimensions of the original coefficient array.
- axisint
Interpolation axis.
Methods
__call__(x[, nu, extrapolate])Evaluate the piecewise polynomial or its derivative.
derivative([nu])Construct a new piecewise polynomial representing the derivative.
antiderivative([nu])Construct a new piecewise polynomial representing the antiderivative.
integrate(a, b[, extrapolate])Compute a definite integral over a piecewise polynomial.
solve([y, discontinuity, extrapolate])Find real solutions of the equation
pp(x) == y.roots([discontinuity, extrapolate])Find real roots of the piecewise polynomial.
extend(c, x)Add additional breakpoints and coefficients to the polynomial.
from_spline(tck[, extrapolate])Construct a piecewise polynomial from a spline
from_bernstein_basis(bp[, extrapolate])Construct a piecewise polynomial in the power basis from a polynomial in Bernstein basis.
construct_fast(c, x[, extrapolate, axis])Construct the piecewise polynomial without making checks.
See also
BPolypiecewise polynomials in the Bernstein basis
Notes
High-order polynomials in the power basis can be numerically unstable. Precision problems can start to appear for orders larger than 20-30.
Array API Standard Support
PPolyhas experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variableSCIPY_ARRAY_API=1and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.Library
CPU
GPU
NumPy
✅
n/a
CuPy
n/a
✅
PyTorch
✅
⛔
JAX
⚠️ no JIT
⛔
Dask
⛔
n/a
The methods
solveandrootsare currently not supported with CuPy.solveandrootswithc.ndim > 2are currently only supported with NumPy.If a ppoly object is called on an input array
xwith namespace different from the namespacexpof the breakpoints and coefficients with which the ppoly object was instantiated, an attempt will be made to coercexto thexpnamespace. If the conversion succeeds, the output will be an array from thexpnamespace. Mixing namespaces in this way is not recommended.See Support for the array API standard for more information.