遍历列表时,顺序是从第零个元素到最后一个元素。但是对于scipy的chebyt函数的返回值,我不清楚迭代如何进行。考虑以下代码:
from scipy.special import chebyt
import numpy as np
ChebyOrder = 5
Coeffs = chebyt(ChebyOrder)
print 'Chebyshev polynomial is: '+repr(Coeffs)
Chebyshev polynomial is: poly1d([ 1.60000000e+01, 5.32907052e-15, -2.00000000e+01,
-5.12827628e-15, 5.00000000e+00, 3.71174867e-16])
但是遍历索引给出:
L = len(Coeffs)
print '(1) Iterating over index: '
for i in range(L+1):
print Coeffs[i]
(1) Iterating over index:
3.71174867001e-16
5.0
-5.12827627586e-15
-20.0
5.3290705182e-15
16.0
遍历该列表可以得出:
print '(2) Iterating over list'
for c in Coeffs:
print c
(2) Iterating over list
16.0
5.3290705182e-15
-20.0
-5.12827627586e-15
5.0
3.71174867001e-16
从打印Chebyshev多项式或遍历列表来看,第零个元素似乎是16(x ^ 4的系数),而通过遍历系数索引,第零个元素似乎是0(x ^ 0的系数)。有人可以解释吗?
Coeffs[i]
是i
多项式中第-次幂的系数(请参阅文档)。
如果您要按照显示的相同顺序repr()
进行迭代,请遍历Coeffs.c
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句