bundles / scipy latest / scipy / interpolate / _interpolate / PPoly / from_spline
classmethod
scipy.interpolate._interpolate:PPoly.from_spline
Summary
Construct a piecewise polynomial from a spline
Parameters
tckA spline, as returned by
splrepor a BSpline object.extrapolate: bool or 'periodic', optionalIf 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. Default is True.
Examples
Construct an interpolating spline and convert it to a `PPoly` instanceimport numpy as np from scipy.interpolate import splrep, PPoly x = np.linspace(0, 1, 11) y = np.sin(2*np.pi*x) tck = splrep(x, y, s=0) p = PPoly.from_spline(tck) isinstance(p, PPoly)✓
from scipy.interpolate import splprep, splev t = np.linspace(0, 1, 11) x = np.sin(2*np.pi*t) y = np.cos(2*np.pi*t) (t, c, k), u = splprep([x, y], s=0)✓
unew = np.arange(0, 1.01, 0.01) out = splev(unew, (t, c, k))✓
polys = [PPoly.from_spline((t, cj, k)) for cj in c] polys[0].c.shape✓
cc = np.dstack([p.c for p in polys]) # has shape = (4, 14, 2) poly = PPoly(cc, polys[0].x) np.allclose(poly(unew).T, # note the transpose to match `splev` out, atol=1e-15)✓
Aliases
-
scipy.interpolate.PPoly.from_spline