numpy.polynomial.polynomial.polyvander#

polynomial.polynomial.polyvander(x, deg)[原始碼]#

給定次數的 Vandermonde 矩陣。

傳回次數為 deg 和樣本點 x 的 Vandermonde 矩陣。Vandermonde 矩陣的定義為

\[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。

Vandermonde 矩陣。傳回的矩陣形狀為 x.shape + (deg + 1,),其中最後一個索引是 x 的冪次。dtype 將與轉換後的 x 相同。

範例

次數為 deg = 5 和樣本點 x = [-1, 2, 3] 的 Vandermonde 矩陣包含 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.]])