bundles / scipy 1.17.1 / scipy / interpolate / _fitpack_py / splrep
function
scipy.interpolate._fitpack_py:splrep
Signature
def splrep ( x , y , w = None , xb = None , xe = None , k = 3 , task = 0 , s = None , t = None , full_output = 0 , per = 0 , quiet = 1 ) Summary
Find the B-spline representation of a 1-D curve.
Extended Summary
Given the set of data points (x[i], y[i]) determine a smooth spline approximation of degree k on the interval xb <= x <= xe.
Parameters
x, y: array_likeThe data points defining a curve
y = f(x).w: array_like, optionalStrictly positive rank-1 array of weights the same length as
xandy. The weights are used in computing the weighted least-squares spline fit. If the errors in theyvalues have standard-deviation given by the vectord, thenwshould be1/d. Default isones(len(x)).xb, xe: float, optionalThe interval to fit. If None, these default to
x[0]andx[-1]respectively.k: int, optionalThe degree of the spline fit. It is recommended to use cubic splines. Even values of
kshould be avoided especially with smallsvalues.1 <= k <= 5.task: {1, 0, -1}, optionalIf
task==0, findtandcfor a given smoothing factor,s.If
task==1findtandcfor another value of the smoothing factor,s. There must have been a previous call withtask=0ortask=1for the same set of data (twill be stored an used internally)If
task=-1find the weighted least square spline for a given set of knots,t. These should be interior knots as knots on the ends will be added automatically.s: float, optionalA smoothing condition. The amount of smoothness is determined by satisfying the conditions:
sum((w * (y - g))**2,axis=0) <= swhereg(x)is the smoothed interpolation of(x,y). The user can usesto control the tradeoff between closeness and smoothness of fit. Largersmeans more smoothing while smaller values ofsindicate less smoothing. Recommended values ofsdepend on the weights,w. If the weights represent the inverse of the standard-deviation ofy, then a goodsvalue should be found in the range(m-sqrt(2*m),m+sqrt(2*m))wheremis the number of datapoints inx,y, andw. default :s=m-sqrt(2*m)if weights are supplied.s = 0.0(interpolating) if no weights are supplied.t: array_like, optionalThe knots needed for
task=-1. If given then task is automatically set to-1.full_output: bool, optionalIf non-zero, then return optional outputs.
per: bool, optionalIf non-zero, data points are considered periodic with period
x[m-1]-x[0]and a smooth periodic spline approximation is returned. Values ofy[m-1]andw[m-1]are not used. The default is zero, corresponding to boundary condition 'not-a-knot'.quiet: bool, optionalNon-zero to suppress messages.
Returns
tck: tupleA tuple
(t,c,k)containing the vector of knots, the B-spline coefficients, and the degree of the spline.fp: array, optionalThe weighted sum of squared residuals of the spline approximation.
ier: int, optionalAn integer flag about splrep success. Success is indicated if
ier<=0. Ifier in [1,2,3], an error occurred but was not raised. Otherwise an error is raised.msg: str, optionalA message corresponding to the integer flag, ier.
Notes
See splev for evaluation of the spline and its derivatives. Uses the FORTRAN routine curfit from FITPACK.
The user is responsible for assuring that the values of x are unique. Otherwise, splrep will not return sensible results.
If provided, knots t must satisfy the Schoenberg-Whitney conditions, i.e., there must be a subset of data points x[j] such that t[j] < x[j] < t[j+k+1], for j=0, 1,...,n-k-2.
This routine zero-pads the coefficients array c to have the same length as the array of knots t (the trailing k + 1 coefficients are ignored by the evaluation routines, splev and BSpline.) This is in contrast with splprep, which does not zero-pad the coefficients.
The default boundary condition is 'not-a-knot', i.e. the first and second segment at a curve end are the same polynomial. More boundary conditions are available in CubicSpline.
Array API Standard Support
splrep is not in-scope for support of Python Array API Standard compatible backends other than NumPy.
See dev-arrayapi for more information.
Examples
You can interpolate 1-D points with a B-spline curve. Further examples are given in :ref:`in the tutorial <tutorial-interpolate_splXXX>`.import numpy as np import matplotlib.pyplot as plt from scipy.interpolate import splev, splrep x = np.linspace(0, 10, 10) y = np.sin(x) spl = splrep(x, y) x2 = np.linspace(0, 10, 200) y2 = splev(x2, spl)✓
plt.plot(x, y, 'o', x2, y2)
✗plt.show()
✓
See also
- BSpline
- BivariateSpline
- UnivariateSpline
- bisplev
- bisplrep
- make_interp_spline
- spalde
- splev
- splint
- splprep
- sproot
Aliases
-
scipy.interpolate.splrep