To create a Vandermonde matrix using numpy library in Python, we can use the numpy.vander
function. The numpy.vander
function accepts two parameters i.e. the input array and the number of columns to create in the output matrix.
Here is an example code snippet that creates a Vandermonde matrix using the numpy.vander
function:
main.py83 chars8 lines
This code will output the following Vandermonde matrix:
main.py61 chars5 lines
In the above code snippet, we created an input array x
with values [1, 2, 3, 4]
and the number of columns to create in the output Vandermonde matrix is n
which is also 4. We then used the numpy.vander
function to create the Vandermonde matrix and stored the result in V
. Finally, we printed the Vandermonde matrix using print(V)
.
gistlibby LogSnag