
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Convert a polynomial to Legendre series in Python
To convert a polynomial to a Legendre series, use the legendre.poly2lag() method in Python Numpy. Convert an array representing the coefficients of a polynomial ordered from lowest degree to highest, to an array of the coefficients of the equivalent Legendre series, ordered from lowest to highest degree. The method returns a 1-D array containing the coefficients of the equivalent Legendre series. The parameter pol, is a 1-D array containing the polynomial coefficients
Steps
At first, import the required library −
import numpy as np from numpy.polynomial import legendre as L
Create an array using the numpy.array() method −
c = np.array([1, 2, 3, 4, 5])
Display the array −
print("Our Array...\n",c)
Check the Dimensions −
print("\nDimensions of our Array...\n",c.ndim)
Get the Datatype −
print("\nDatatype of our Array object...\n",c.dtype)
Get the Shape −
print("\nShape of our Array object...\n",c.shape)
To convert a polynomial to a Legendre series, use the legendre.poly2lag() method in Python Numpy −
print("\nResult (polynomial to legendre)...\n",L.poly2leg(c))
Example
import numpy as np from numpy.polynomial import legendre as L # Create an array using the numpy.array() method c = np.array([1, 2, 3, 4, 5]) # Display the array print("Our Array...\n",c) # Check the Dimensions print("\nDimensions of our Array...\n",c.ndim) # Get the Datatype print("\nDatatype of our Array object...\n",c.dtype) # Get the Shape print("\nShape of our Array object...\n",c.shape) # To convert a polynomial to a Legendre series, use the legendre.poly2lag() method in Python Numpy print("\nResult (polynomial to legendre)...\n",L.poly2leg(c))
Output
Our Array... [1 2 3 4 5] Dimensions of our Array... 1 Datatype of our Array object... int64 Shape of our Array object... (5,) Result (polynomial to legendre)... [3. 4.4 4.85714286 1.6 1.14285714]
- Related Articles
- Convert a Legendre series to a polynomial in Python
- Convert a polynomial to Hermite series in Python
- Convert a polynomial to Laguerre series in Python
- Convert a polynomial to Hermite_e series in Python
- Convert a Chebyshev series to a polynomial in Python
- Convert a polynomial to a Chebyshev series in Python
- Convert a Hermite series to a polynomial in Python
- Convert a Laguerre series to a polynomial in Python
- Convert a Hermite_e series to a polynomial in Python
- Differentiate a Legendre series in Python
- Integrate a Legendre series in Python
- Raise a Legendre series to a power in Python
- Add one Legendre series to another in Python
- Multiply one Legendre series to another in Python
- Evaluate a Legendre series at points x in Python

Advertisements