What is the numpy.vander() function from NumPy in Python?
Overview
The vander() function in Python is simply used to generate a Vandermonde matrix.
Syntax
numpy.vander(x, N=None, increasing=False)
Parameter value
The vander() function takes the following parameter values.
x: This represents the1-Dinput array.N: This represents the number of columns in the output matrix or array.increasing: This takes a Boolean value and represents the power of the columns. IfTrue, the powers increase from left to right, ifFalseby default, they are reversed.
Return values
The vander() function returns a Vandermonde matrix.
Code example
import numpy as np# creating an arraymyarray = np.array([1, 2, 3, 4, 5])# implementing the vander() functionmymatrix = np.vander(myarray, N=3, increasing=False)print(mymatrix)
Explanation
- Line 1: We import the
numpymodule. - Line 4: We create an array,
myarray, having5elements. - Line 7: We implement the
vander()function on the arraymyarrayusing3, as the number of columns of the output array and a default value for theincreasingparameter. The output is assigned to a new variable,mymatrix. - Line 9: We print the Vandermonde matrix
mymatrix.