Open In App

Convert a Hermite series to a polynomial in Python

Last Updated : 09 Dec, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, we will be looking at the step-wise procedure to convert a Hermite series to a polynomial in Python.

NumPy.herm2poly method

To convert a Hermite series to a polynomial, use the np.herm2poly() function from the Numpy package of python. Convert the given array representing the coefficients of a Hermite series, ordered from lowest degree to highest, to an array of the coefficients of the equivalent polynomial (relative to the “standard” basis) ordered from lowest to the highest degree.

Syntax: np.herm2poly(hermite series)

Parameter:

  • hermite series: 1-D array

Return: Return the coefficient of polynomial.

Stepwise Implementation:

Step 1: In this step, we are importing the required packages needed.

Python3
import numpy as np
from numpy.polynomial import hermite

Step 2: In this step, we are creating an array containing 10 coefficients and displaying it.

Python3
gfg = np.array([1,2,3,4,5,6,7,8,9,10])

print(gfg)

Output:

[ 1  2  3  4  5  6  7  8  9 10]

Step 3: In this step we are checking the dimension and the datatype of the array created in step 2. 

Python3
print("Dimensions of our Array:-",gfg.ndim)

print("\nDatatype of  Array:-",gfg.dtype)

Output:

Dimensions of our Array:- 1
Datatype of  Array:- int64

Step 4: In this step, we are checking the shape of the array created in step 2.

Python3
print("\nShape of  Array:-",gfg.shape)

Output:

Shape of  Array:- (10,)

Step 5: This is the final step where we are using the np.herm2poly()  function to Hermite series to a polynomial:

Python3
print("\n Converting Hermite series to a polynomial", 
      hermite.herm2poly(gfg))

Example:

This method returns a 1-D array containing the coefficients of the equivalent polynomial (relative to the “standard” basis) ordered from lowest order term to highest. The parameter passed is a 1-D array containing the Hermite series coefficients, ordered from the lowest order term to the highest.

Python3
import numpy as np
from numpy.polynomial import hermite

gfg = np.array([1,2,3,4,5,6,7,8,9,10])

print(gfg)
print("\nDimensions of our Array:-",gfg.ndim)
print("\nDatatype of  Array:-",gfg.dtype)
print("\nShape of  Array:-",gfg.shape)
print("\n Converting Hermite series to a polynomial",hermite.herm2poly(gfg))

Output:

[ 1  2  3  4  5  6  7  8  9 10]

Dimensions of our Array:- 1

Datatype of  Array:- int64

Shape of  Array:- (10,)

 Converting Hermite series to a polynomial [  14335.  289636. -116148. -780448.  117680.  473280.  -31808.  -91136. 2304.    5120.]


Next Article
Practice Tags :

Similar Reads