# Remove small trailing coefficients from Laguerre polynomial in Python

PythonNumpyServer Side ProgrammingProgramming

To remove small trailing coefficients from Laguerre polynomial, use the laguerre.lagtrim() method in Python numpy. 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 “Small” means “small in absolute value” and is controlled by the parameter tol; “trailing” means highest order coefficient(s), e.g., in [0, 1, 1, 0, 0] (which represents 0 + x + x**2 + 0*x**3 + 0*x**4) both the 3-rd and 4-th order coefficients would be “trimmed.” The parameter c is a 1-d array of coefficients, ordered from lowest order to highest. The parameter tol is Trailing elements with absolute value less than or equal to tol are removed.

## Steps

At first, import the required library −

import numpy as np
from numpy.polynomial import hermite as H

Create an array using the numpy.array() method. This is the 1-d array of coefficients −

c = np.array([0,5,0, 0,9,0])

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 remove small trailing coefficients from Laguerre polynomial, use the laguerre.lagtrim() method in Python numpy −

print("\nResult...\n",L.lagtrim(c))

## Example

import numpy as np
from numpy.polynomial import laguerre as L

# Create an array using the numpy.array() method
# This is the 1-d array of coefficients
c = np.array([0,5,0, 0,9,0])

# 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 remove small trailing coefficients from Laguerre polynomial, use the laguerre.lagtrim() method in Python numpy.
print("\nResult...\n",L.lagtrim(c))

## Output

Our Array...
[0 5 0 0 9 0]

Dimensions of our Array...
1

Datatype of our Array object...
int64

Shape of our Array object...
(6,)

Result...
[0. 5. 0. 0. 9.]
Updated on 07-Mar-2022 05:02:29