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 是标量,则将其转换为一维数组.

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.]])