Python | Numpy np.poly2leg() method

With the help of np.poly2leg() method, we can get the Legendre series coefficient from a given polynomial.

Syntax : np.poly2leg(polynomial)
Return : Return the coefficient of Legendre series.

Example #1 :
In this example we can see that by using np.poly2leg() method, we are able to get the coefficients of Legendre series from polynomial using this method.

filter_none

edit
close

play_arrow

link
brightness_4
code

# import numpy and poly2leg
import numpy as np
from numpy.polynomial.legendre import poly2leg
  
arr = np.array([0.1, 0.2, 0.3, 0.4, 0.5])
# using np.poly2leg() method
ans = poly2leg(arr)
  
print(ans)

chevron_right


Output :

[ 0.3 0.44 0.48571429 0.16 0.11428571]



Example #2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

# import numpy and poly2leg
import numpy as np
from numpy.polynomial.legendre import poly2leg
  
arr = np.array([-0.5, -0.4, -0.3, -0.2, -0.1, 0, 0.1, 0.2, 0.3, 0.4, 0.5])
# using np.poly2leg() method
ans = poly2leg(arr)
  
print(ans)

chevron_right


Output :

[-0.52692641 -0.34424242 0.08651349 0.16149184 0.27684316 0.13948718
0.13127578 0.03905114 0.02952276 0.00421226 0.00277122]

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.