本文簡要介紹 python 語言中 scipy.interpolate.BSpline.design_matrix
的用法。
用法:
classmethod BSpline.design_matrix(x, t, k, extrapolate=False)#
將設計矩陣作為 CSR 格式的稀疏數組返回。
- x: 數組, 形狀 (n,)
評估樣條曲線的點。
- t: 數組, 形狀 (nt,)
已排序的一維結數組。
- k: int
B-spline 度數。
- extrapolate: bool 或 ‘periodic’,可選
是否根據第一個和最後一個間隔進行推斷或引發錯誤。如果‘periodic’,則使用周期性外推法。默認值為 False。
- design_matrix: csr_array對象
CSR 格式的稀疏矩陣,其中每行包含輸入行的所有基本元素(第一行 = x[0], … 的基本元素,最後一行 = 基本元素 x[-1])。
參數 ::
返回 ::
注意:
在設計矩陣的每一行中,所有基本元素都在特定點進行評估(第一行 - x[0],...,最後一行 - x[-1])。
nt 是節點向量的長度:隻要有 nt - k - 1 個基元素,nt 應不小於 2 * k + 2 才能具有至少 k + 1 個基元素。
越界 x 引發 ValueError。
例子:
為 B-spline 構建設計矩陣
>>> from 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() [[1. , 0. , 0. , 0. ], [0.2962963 , 0.44444444, 0.22222222, 0.03703704], [0.03703704, 0.22222222, 0.44444444, 0.2962963 ], [0. , 0. , 0. , 1. ]]
為某個節點向量構造一個設計矩陣
>>> 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 [[0.5, 0.5, 0. , 0. , 0. ], [0. , 0.5, 0.5, 0. , 0. ], [0. , 0. , 0.5, 0.5, 0. ], [0. , 0. , 0. , 0.5, 0.5]]
這個結果等同於在稀疏格式中創建的結果
>>> 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) True
相關用法
- Python SciPy BSpline.basis_element用法及代碼示例
- Python SciPy BSpline.integrate用法及代碼示例
- Python SciPy BivariateSpline.ev用法及代碼示例
- Python SciPy BPoly.from_derivatives用法及代碼示例
- Python SciPy Bounds.residual用法及代碼示例
- Python SciPy BivariateSpline.__call__用法及代碼示例
- Python SciPy BinomTestResult.proportion_ci用法及代碼示例
- Python SciPy BarycentricInterpolator.derivatives用法及代碼示例
- Python SciPy interpolate.make_interp_spline用法及代碼示例
- Python SciPy stats.anderson用法及代碼示例
- Python SciPy ClusterNode.pre_order用法及代碼示例
- Python SciPy stats.iqr用法及代碼示例
- Python SciPy FortranFile.read_record用法及代碼示例
- Python SciPy ndimage.correlate用法及代碼示例
- Python SciPy special.exp1用法及代碼示例
- Python SciPy special.expn用法及代碼示例
- Python SciPy signal.czt_points用法及代碼示例
- Python SciPy interpolate.krogh_interpolate用法及代碼示例
- Python SciPy ndimage.morphological_gradient用法及代碼示例
- Python SciPy distance.sokalmichener用法及代碼示例
- Python SciPy linalg.eigvalsh_tridiagonal用法及代碼示例
- Python SciPy linalg.cdf2rdf用法及代碼示例
- Python SciPy csc_array.diagonal用法及代碼示例
- Python SciPy fft.idctn用法及代碼示例
- Python SciPy linalg.LaplacianNd用法及代碼示例
注:本文由純淨天空篩選整理自scipy.org大神的英文原創作品 scipy.interpolate.BSpline.design_matrix。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。