numpy.polynomial.polynomial.polyvander#

polynomial.polynomial.polyvander(x, deg)[source]#

给定次数的范德蒙矩阵。

返回次数为 deg 且样本点为 x 的范德蒙矩阵。范德蒙矩阵定义为

\[V[..., i] = x^i,\]

其中 0 <= i <= degV 的前导索引指示 x 的元素,最后一个索引是 x 的幂。

如果 c 是一个长度为 n + 1 的 1-D 系数数组,并且 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 相同。

另请参阅

polyvander2d, polyvander3d

示例

次数为 deg = 5 且样本点为 x = [-1, 2, 3] 的范德蒙矩阵包含 x 的从 0 到 5 的逐元素幂作为其列。

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