numpy.vander#
- numpy.vander(x, N=None, increasing=False)[源代码]#
生成范德蒙矩阵.
输出矩阵的列是输入向量的幂.幂的顺序由 increasing 布尔参数确定.具体来说,当 increasing 为 False 时,第 i 个输出列是输入向量的每个元素提升到
N - i - 1的幂.这种矩阵的每一行都是一个几何级数,以 Alexandre-Theophile Vandermonde 的名字命名.- 参数:
- xarray_like
1-D 输入数组.
- N整数,可选
输出中的列数.如果未指定 N ,则返回一个方阵(
N = len(x)).- increasingbool, 可选
列的幂的顺序.如果为 True,则幂从左到右递增,如果为 False(默认),则幂反转.
- 返回:
- outndarray
范德蒙矩阵.如果 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]])
方阵范德蒙矩阵的行列式是输入向量的值之间差的乘积:
>>> np.linalg.det(np.vander(x)) 48.000000000000043 # may vary >>> (5-3)*(5-2)*(5-1)*(3-2)*(3-1)*(2-1) 48