Open In App

Remove Small Trailing Coefficients from Hermite Polynomial in Python

Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will be looking toward the approach for removing small trailing coefficients from Hermite polynomial in Python and NumPy.

Example:

Array:[0,1,0,0,2,3,4,5,0,0]

Result:[0., 1., 0., 0., 2., 3., 4., 5.]

 Numpy np.hermtrim() method

To remove small trailing coefficients from Hermite polynomial, the user needs to call the hermite.hermtrim() method of the Numpy library in Python. The method returns a 1-d array with trailing zeros removed. If the resulting series would be empty, a series containing a single zero is returned. The parameter series is a 1-d array of coefficients, ordered from lowest order to highest and the parameter tol is Trailing elements with absolute value less than or equal to tol are removed.

    Syntax : np.hermtrim(series,tol)

   Parameters:

  • series: array of coefficient
  •  tol : Trailing elements with absolute value less than or equal to tol are removed.

   Return : Return the coefficients of series after trimming.

Example:

In this example, we created an array of 10 data points of one dimension, then with the use of the hermite.hermtrim() method we pass the required parameters where the tol parameter is not passed and the functionality is working on default to remove small trailing coefficients from Hermite polynomial in Python.

Python3




import numpy as np
from numpy.polynomial import hermite 
  
a = np.array([0,1,0,0,2,3,4,5,0,0])
  
# Dimensions of Array
print("\nDimensions of Array:\n",a.ndim)
  
# Shape of the array
print("\nShape of Array:\n",a.shape)
  
# To  remove small trailing
# coefficients from Hermite polynomial
print("\nResult:\n",hermite.hermtrim(a))


Output:

Dimensions of Array:
 1

Shape of Array:
 (10,)

Result:
 [0. 1. 0. 0. 2. 3. 4. 5.]

Example:

In this example, we created an array of 10 data points of one dimension, then with the use of the hermite.hermtrim() method we pass the required parameters where the tol parameter passed with value 1 to remove small trailing coefficients from Hermite polynomial in Python.

Python3




import numpy as np
from numpy.polynomial import hermite 
  
a = np.array([1,1,1,1,2,3,4,5,1,1])
  
# Dimensions of Array
print("\nDimensions of Array:\n",a.ndim)
  
# Shape of the array
print("\nShape of Array:\n",a.shape)
  
# To  remove small trailing coefficients from Hermite polynomial
print("\nResult:\n",hermite.hermtrim(a,1))


Output:

Dimensions of Array:
 1

Shape of Array:
 (10,)

Result:
 [1. 1. 1. 1. 2. 3. 4. 5.]


Last Updated : 21 Apr, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads