bundles / scipy 1.17.1 / scipy / interpolate / _bsplines / BSpline / design_matrix
classmethod
scipy.interpolate._bsplines:BSpline.design_matrix
Summary
Returns a design matrix as a CSR format sparse array.
Parameters
x: array_like, shape (n,)Points to evaluate the spline at.
t: array_like, shape (nt,)Sorted 1D array of knots.
k: intB-spline degree.
extrapolate: bool or 'periodic', optionalWhether to extrapolate based on the first and last intervals or raise an error. If 'periodic', periodic extrapolation is used. Default is False.
Returns
design_matrix: `csr_array` objectSparse matrix in CSR format where each row contains all the basis elements of the input row (first row = basis elements of x[0], ..., last row = basis elements x[-1]).
Notes
In each row of the design matrix all the basis elements are evaluated at the certain point (first row - x[0], ..., last row - x[-1]).
nt is a length of the vector of knots: as far as there are nt - k - 1 basis elements, nt should be not less than 2 * k + 2 to have at least k + 1 basis element.
Out of bounds x raises a ValueError.
Examples
Construct a design matrix for a B-splinefrom scipy.interpolate import make_interp_spline, BSpline import numpy as np x = np.linspace(0, np.pi * 2, 4) y = np.sin(x) k = 3 bspl = make_interp_spline(x, y, k=k) design_matrix = bspl.design_matrix(x, bspl.t, k)✓
design_matrix.toarray()
✗k = 2 t = [-1, 0, 1, 2, 3, 4, 5, 6] x = [1, 2, 3, 4] design_matrix = BSpline.design_matrix(x, t, k).toarray()✓
design_matrix
✗c = np.eye(len(t) - k - 1) design_matrix_gh = BSpline(t, c, k)(x) np.allclose(design_matrix, design_matrix_gh, atol=1e-14)✓
Aliases
-
scipy.interpolate.BSpline.design_matrix