flopscope.numpy.vander
fnp.vander(x, N=None, increasing=False)[flopscope source][numpy source]
Generate a Vandermonde matrix.
Adapted from NumPy docs np.vander
Vandermonde matrix; cost = len(x)*(N-1).
The columns of the output matrix are powers of the input vector. The
order of the powers is determined by the increasing boolean argument.
Specifically, when increasing is False, the i-th output column is
the input vector raised element-wise to the power of N - i - 1. Such
a matrix with a geometric progression in each row is named for Alexandre-
Theophile Vandermonde.
Parameters
- x:array_like
1-D input array.
- N:int, optional
Number of columns in the output. If
Nis not specified, a square array is returned (N = len(x)).- increasing:bool, optional
Order of the powers of the columns. If True, the powers increase from left to right, if False (the default) they are reversed.
Returns
- out:ndarray
Vandermonde matrix. If
increasingis False, the first column isx^(N-1), the secondx^(N-2)and so forth. Ifincreasingis True, the columns arex^0, x^1, ..., x^(N-1).
See also
- polynomial.polynomial.polyvander
Examples
>>> import flopscope.numpy as fnp
>>> x = flops.array([1, 2, 3, 5])
>>> N = 3
>>> flops.vander(x, N)
array([[ 1, 1, 1],
[ 4, 2, 1],
[ 9, 3, 1],
[25, 5, 1]])>>> flops.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 = flops.array([1, 2, 3, 5])
>>> flops.vander(x)
array([[ 1, 1, 1, 1],
[ 8, 4, 2, 1],
[ 27, 9, 3, 1],
[125, 25, 5, 1]])
>>> flops.vander(x, increasing=True)
array([[ 1, 1, 1, 1],
[ 1, 2, 4, 8],
[ 1, 3, 9, 27],
[ 1, 5, 25, 125]])The determinant of a square Vandermonde matrix is the product of the differences between the values of the input vector:
>>> flops.linalg.det(flops.vander(x))
48.000000000000043 # may vary
>>> (5-3)*(5-2)*(5-1)*(3-2)*(3-1)*(2-1)
48