numpy.vander#
- numpy.vander(x, N=None, increasing=False)[原始碼]#
產生 Vandermonde 矩陣。
輸出矩陣的各列是輸入向量的次方。次方的順序由布林參數 increasing 決定。具體來說,當 increasing 為 False 時,第 i 個輸出列是輸入向量逐元素取
N - i - 1
次方。這種每行都是幾何級數的矩陣以 Alexandre-Theophile Vandermonde 命名。- 參數:
- xarray_like
一維輸入陣列。
- Nint,選用
輸出中的欄數。如果未指定 N,則會傳回方形陣列 (
N = len(x)
)。- increasingbool,選用
欄的次方順序。如果為 True,次方會從左到右遞增;如果為 False(預設值),則會反轉。
- 傳回值:
- outndarray
Vandermonde 矩陣。如果 increasing 為 False,則第一欄為
x^(N-1)
,第二欄為x^(N-2)
,依此類推。如果 increasing 為 True,則欄為x^0, x^1, ..., x^(N-1)
。
範例
>>> import numpy as np >>> x = np.array([1, 2, 3, 5]) >>> N = 3 >>> np.vander(x, N) array([[ 1, 1, 1], [ 4, 2, 1], [ 9, 3, 1], [25, 5, 1]])
>>> np.column_stack([x**(N-1-i) for i in range(N)]) array([[ 1, 1, 1], [ 4, 2, 1], [ 9, 3, 1], [25, 5, 1]])
>>> x = np.array([1, 2, 3, 5]) >>> np.vander(x) array([[ 1, 1, 1, 1], [ 8, 4, 2, 1], [ 27, 9, 3, 1], [125, 25, 5, 1]]) >>> np.vander(x, increasing=True) array([[ 1, 1, 1, 1], [ 1, 2, 4, 8], [ 1, 3, 9, 27], [ 1, 5, 25, 125]])
方形 Vandermonde 矩陣的行列式是輸入向量值之間差異的乘積
>>> np.linalg.det(np.vander(x)) 48.000000000000043 # may vary >>> (5-3)*(5-2)*(5-1)*(3-2)*(3-1)*(2-1) 48