numpy.polynomial.polynomial.polyvander#
- polynomial.polynomial.polyvander(x, deg)[源代码]#
给定阶数的范德蒙矩阵.
返回阶数为 deg 和采样点 x 的范德蒙矩阵.范德蒙矩阵定义为
\[V[..., i] = x^i,\]其中
0 <= i <= deg. V 的前导索引索引 x 的元素,最后一个索引是 x 的幂.如果 c 是长度为
n + 1的系数的一维数组, V 是矩阵V = polyvander(x, n),那么np.dot(V, c)和polyval(x, c)在舍入误差范围内是相同的.这种等价性对于最小二乘拟合以及对大量相同阶数和采样点的多项式进行求值都很有用.- 参数:
- xarray_like
点数组.dtype 被转换为 float64 或 complex128,具体取决于是否有任何元素是复数. 如果 x 是标量,则将其转换为 1-D 数组.
- degint
结果矩阵的阶数.
- 返回:
- vanderndarray.
范德蒙矩阵.返回的矩阵的形状是
x.shape + (deg + 1,),其中最后一个索引是 x 的幂.dtype 将与转换后的 x 相同.
参见
示例
阶数为
deg = 5和采样点x = [-1, 2, 3]的 (1D) 范德蒙矩阵包含从 0 到 5 的 x 的逐元素幂作为其列.>>> from numpy.polynomial import polynomial as P >>> x, deg = [-1, 2, 3], 5 >>> P.polyvander(x=x, deg=deg) array([[ 1., -1., 1., -1., 1., -1.], [ 1., 2., 4., 8., 16., 32.], [ 1., 3., 9., 27., 81., 243.]])