- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Remove small trailing coefficients from Chebyshev polynomial in Python

To remove small trailing coefficients from Chebyshev polynomial, use the chebyshev.chebtrim() 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 chebyshev as C

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 Chebyshev polynomial, use the chebyshev.chebtrim() method in Python Numpy −

print("\nResult...\n",C.chebtrim((c)))

## Example

import numpy as np from numpy.polynomial import chebyshev as C # 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 Chebyshev polynomial, use the chebyshev.chebtrim() method in Python Numpy. print("\nResult...\n",C.chebtrim((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.]

- Related Questions & Answers
- Remove small trailing coefficients from a polynomial in Python
- Remove small trailing coefficients from Hermite polynomial in Python
- Remove small trailing coefficients from Laguerre polynomial in Python
- Remove small trailing coefficients from Legendre polynomial in Python
- Remove small trailing coefficients from Hermite_e polynomial in Python
- Differentiate a Chebyshev series with multidimensional coefficients in Python
- Differentiate a polynomial with multidimensional coefficients in Python
- Remove Trailing Zeros from string in C++
- Convert a Chebyshev series to a polynomial in Python
- Convert a polynomial to a Chebyshev series in Python
- Evaluate a polynomial when coefficients are multi-dimensional in Python
- Generate a Vandermonde matrix of the Chebyshev polynomial in Python
- Differentiate a Chebyshev series with multidimensional coefficients over specific axis in Python
- Differentiate a Chebyshev series with multidimensional coefficients over axis 1 in Python
- Differentiate a polynomial with multidimensional coefficients over axis 1 in Python