numpy.vander#

numpy.vander(x,N=None,increasing=False)[source]#

Generate a Vandermonde matrix.

The columns of the output matrix are powers of the input vector. Theorder of the powers is determined by theincreasing boolean argument.Specifically, whenincreasing is False, thei-th output column isthe input vector raised element-wise to the power ofN-i-1. Sucha matrix with a geometric progression in each row is named for Alexandre-Theophile Vandermonde.

Parameters:
xarray_like

1-D input array.

Nint, optional

Number of columns in the output. IfN is not specified, a squarearray is returned (N=len(x)).

increasingbool, optional

Order of the powers of the columns. If True, the powers increasefrom left to right, if False (the default) they are reversed.

Returns:
outndarray

Vandermonde matrix. Ifincreasing is False, the first column isx^(N-1), the secondx^(N-2) and so forth. Ifincreasing isTrue, the columns arex^0,x^1,...,x^(N-1).

Examples

>>>importnumpyasnp>>>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)foriinrange(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]])

The determinant of a square Vandermonde matrix is the productof the differences between the values of the input vector:

>>>np.linalg.det(np.vander(x))48.000000000000043 # may vary>>>(5-3)*(5-2)*(5-1)*(3-2)*(3-1)*(2-1)48
On this page