Python | Numpy np.legvander() method

np.legvander() method is used to returns the Vandermonde matrix of degree deg and sample points x.

Syntax : np.legvander(x, deg)
Parameters:
x :[ array_like ] Array of points. The dtype is converted to float64 or complex128 depending on whether any of the elements are complex. If x is scalar it is converted to a 1-D array.
deg :[int] Degree of the resulting matrix.

Return : Return the matrix having size i.e array.size + (degree + 1).



Example #1 :
In this example we can see that by using np.legvander() method, we are able to get the pseudo-vandermonde matrix using this method.

filter_none

edit
close

play_arrow

link
brightness_4
code

# import numpy
import numpy as np
import numpy.polynomial.legendre as geek
  
# using np.legvander() method
ans = geek.legvander((1, 3, 5, 7), 2)
  
print(ans)

chevron_right


Output :

[[ 1. 1. 1.]
[ 1. 3. 13.]
[ 1. 5. 37.]
[ 1. 7. 73.]]

Example #2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

# import numpy
import numpy as np
import numpy.polynomial.legendre as geek
  
ans = geek.legvander((1, 2, 3, 4), 3)
  
print(ans)

chevron_right


Output :

[[ 1. 1. 1. 1. ]
[ 1. 2. 5.5 17. ]
[ 1. 3. 13. 63. ]
[ 1. 4. 23.5 154. ]]



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.