Friday, October 24, 2025
HomeLanguagesPython Program to Remove Small Trailing Coefficients from Chebyshev Polynomial

Python Program to Remove Small Trailing Coefficients from Chebyshev Polynomial

Given a Chebyshev Polynomial, the task is to Remove Small Trailing Coefficients from Chebyshev Polynomial in Python and NumPy.

Example

Input: [-1, 0, 2, 0]

Output: [-1.  0.  2.]

Explanation: One dimensional array in which trailing zeroes are removed.

NumPy.polynomial.Chebyshev method

Python provides a method called NumPy.polynomial.Chebyshev removes the trailing zeroes in a polynomial. This method accepts a one-dimensional (1D) array that consists of coefficients of a polynomial starting from lower order to higher order and returns a one-dimensional (1D) array in which trailing zeroes are removed. Let’s consider a polynomial 0x3+2x2+0x-1 and for the given polynomial, the coefficient array is [-1, 0, 2, 0] starting from lower-order constant to higher-order x3. The chebtrim method will remove the trailing zeroes and return the resultant coefficient array.

Syntax: numpy.polynomial.chebyshev.chebtrim(arr)

Parameter:

  • arr: 1-d array of coefficients.

Returns: trimmed ndarray.

Example 1:

Python program to remove the small trailing coefficients for the polynomial 0x3+2x2+0x-1.

Python3




# import necessary packages
import numpy as np
import numpy.polynomial.chebyshev as c
  
# create 1D array of
# coefficients for the given polynomial
coeff = np.array([-1, 0, 2, 0])
  
# returns array where trailing zeroes 
# got removed
print(c.chebtrim(coeff))


Output:

The x3 coefficient is removed because there is no significance for the higher-order term as its coefficient is zero.

[-1.  0.  2.]

Example 2:

Python program to remove the small trailing coefficients for the polynomial 0x5+0x4+x3-x2+10x+0.

Python3




# import necessary packages
import numpy as np
import numpy.polynomial.chebyshev as c
  
# create 1D array of coefficients for the given polynomial
coeff = np.array([0, 10, -1, 1, 0, 0])
  
# returns array where trailing zeroes got removed
print(c.chebtrim(coeff))


Output:

The coefficients of x4 and x5 are removed by the chebtrim method from the input array of coefficients.

[ 0. 10. -1.  1.]

Example 3:

Python program to remove the small trailing coefficients for the polynomial 4x4+3x3-2x2-1x+0.

Python3




# import necessary packages
import numpy as np
import numpy.polynomial.chebyshev as c
  
# create 1D array of coefficients for the 
# given polynomial
coeff = np.array([0, -1, -2, 3, 4])
  
# returns array where trailing zeroes got removed
print(c.chebtrim(coeff))


Output:

Here no coefficients are removed by the chebtrim method as there are no trailing zeroes.

[ 0. -1. -2.  3.  4.]
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS