This is a pre-release version (latest). Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy latest / numpy / polynomial / polyutils / trimcoef

function

numpy.polynomial.polyutils:trimcoef

source: build-install/usr/lib/python3.14/site-packages/numpy/polynomial/polyutils.py :144

Signature

def   trimcoef ( c tol = 0 )

Summary

Remove "small" "trailing" coefficients from a polynomial.

Extended Summary

"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."

Parameters

c : array_like

1-d array of coefficients, ordered from lowest order to highest.

tol : number, optional

Trailing (i.e., highest order) elements with absolute value less than or equal to tol (default value is zero) are removed.

Returns

trimmed : ndarray

1-d array with trailing zeros removed. If the resulting series would be empty, a series containing a single zero is returned.

Raises

: ValueError

If tol < 0

Examples

from numpy.polynomial import polyutils as pu
pu.trimcoef((0,0,3,0,5,0,0))
pu.trimcoef((0,0,1e-3,0,1e-5,0,0),1e-3) # item == tol is trimmed
i = complex(0,1) # works for complex
pu.trimcoef((3e-4,1e-3*(1-i),5e-4,2e-5*(1+i)), 1e-3)

Aliases

  • numpy.polynomial.chebyshev.chebtrim