【发布时间】:2015-08-23 05:34:46
【问题描述】:
我正在尝试计算 kth Chebyshev 多项式的系数。为此,我们只需将 k 设置为 5。到目前为止,我有以下内容:
a = (0,0,0,0,0,1) #selects the 5th Chebyshev polynomial
p = numpy.polynomial.chebyshev.Chebyshev(a) #type here is Chebyshev
cpoly = numpy.polynomial.chebyshev.cheb2poly(p) #trying to convert to Poly
print cpoly.all_coeffs()
第二行运行后,我有一个Chebyshev 类型的对象,正如预期的那样。但是,第三行无法转换为Poly 类型,而是转换为numpy.ndarray 类型。因此,我收到一条错误消息,指出 ndarray 没有属性 all_coeffs。
有人知道如何解决这个问题吗?
【问题讨论】:
-
什么是“NP”包?我想它代表 umpy... 你确定 cpoly 有 'all_coeffs' 方法吗?
-
你检查过文档吗?对于
cheb2poly: -->Convert an array representing the coefficients of a Chebyshev series, ordered from lowest degree to highest, to an array of the coefficients of the equivalent polynomial -
@Zohar 是的,它代表 numpy ..应该在发布之前转换它。 cpoly 没有那个方法。但我不确定如何定义 cpoly 以便它这样做。
-
@cel 如果 cheb2poly 不是正确的调用方法,你知道哪个是正确的吗?
-
我认为您只是在滥用该方法。文档明确指出您应该传递系数并获取系数。您实际上传递了一个多项式对象并期望得到一个多项式对象,这根本不是该方法所做的。
标签: python numpy polynomial-math