NdPPoly#
- class scipy.interpolate.NdPPoly(c, x, extrapolate=None)[source]#
Piecewise tensor product polynomial.
The value at point
xp = (x', y', z', ...)is evaluated by first computing the interval indices i such that:x[0][i[0]] <= x' < x[0][i[0]+1] x[1][i[1]] <= y' < x[1][i[1]+1] ...
and then computing:
S = sum(c[k0-m0-1,...,kn-mn-1,i[0],...,i[n]] * (xp[0] - x[0][i[0]])**m0 * ... * (xp[n] - x[n][i[n]])**mn for m0 in range(k[0]+1) ... for mn in range(k[n]+1))
where
k[j]is the degree of the polynomial in dimension j. This representation is the piecewise multivariate power basis.- Parameters:
- cndarray, shape (k0, …, kn, m0, …, mn, …)
Polynomial coefficients, with polynomial order kj and mj+1 intervals for each dimension j.
- xndim-tuple of ndarrays, shapes (mj+1,)
Polynomial breakpoints for each dimension. These must be sorted in increasing order.
- extrapolatebool, optional
Whether to extrapolate to out-of-bounds points based on first and last intervals, or to return NaNs. Default: True.
- Attributes:
- xtuple of ndarrays
Breakpoints.
- cndarray
Coefficients of the polynomials.
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(ranges[, extrapolate])Compute a definite integral over a piecewise polynomial.
integrate_1d(a, b, axis[, extrapolate])Compute NdPPoly representation for one dimensional definite integral.
construct_fast(c, x[, extrapolate])Construct the piecewise polynomial without making checks.
See also
PPolypiecewise polynomials in 1D
Notes
High-order polynomials in the power basis can be numerically unstable.
Array API Standard Support
NdPPolyhas 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
⚠️ no JIT
⛔
Dask
⛔
n/a
If an ndppoly object is called on input arrays
xwith namespace different from the namespacexpof the breakpoints and coefficients with which the ndppoly 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 Array API coverage for more information.