numpy.polynomial.polynomial.polyvander#

polynomial.polynomial.polyvander(x, deg)[源代码]#

给定次数的范德蒙德矩阵。

返回给定次数 deg 和采样点 x 的范德蒙德矩阵。范德蒙德矩阵定义为

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

其中 0 <= i <= degV 的前导索引是 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 相同。

另请参阅

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