numpy.polynomial.legendre.legtrim#
- polynomial.legendre.legtrim(c, tol=0)[source]#
从多项式中移除“小”的“尾部”系数。
“小”指“绝对值小”,并由参数 tol 控制;“尾部”指最高阶系数,例如在
[0, 1, 1, 0, 0]
(表示0 + x + x**2 + 0*x**3 + 0*x**4
)中,第 3 阶和第 4 阶系数都会被“修剪”。- 参数:
- c类数组对象
1 维系数数组,从最低阶到最高阶排列。
- tol数字,可选
尾部(即最高阶)元素,其绝对值小于或等于 tol (默认值为零)将被移除。
- 返回:
- trimmedndarray
已移除尾部零的 1 维数组。如果结果序列为空,则返回包含单个零的序列。
- 引发:
- ValueError
如果 tol < 0
示例
>>> from numpy.polynomial import polyutils as pu >>> pu.trimcoef((0,0,3,0,5,0,0)) array([0., 0., 3., 0., 5.]) >>> pu.trimcoef((0,0,1e-3,0,1e-5,0,0),1e-3) # item == tol is trimmed array([0.]) >>> i = complex(0,1) # works for complex >>> pu.trimcoef((3e-4,1e-3*(1-i),5e-4,2e-5*(1+i)), 1e-3) array([0.0003+0.j , 0.001 -0.001j])