我用poly1d和polyder来返回一个简单多项式的导数。
3 2
1 x + 1 x + 1 x + 1我看到这两个命令的简单组合并没有按照正确的顺序使用系数。
print(np.poly1d(P.polyder(c)))我能用这样的衬垫吗?
print(np.poly1d(P.polyder(c)))所以像上面这样的系数是正确的顺序吗?
Below is my code and output:
import numpy as np
from numpy.polynomial import polynomial as P
print("")
c = (1, 1, 1, 1)
print("the array of coefficients for the polynomial")
print(c)
print("")
print("polynomial with coefficients and exponents")
print(np.poly1d(c))
print("")
print("array of coefficients of derivative of polynomial: lowest order coming first in the array")
d_c = P.polyder(c)
print(d_c)
print("")
print("reversing the array of coefficients for the derivative of the polynomial")
d_c = d_c[::-1]
print(d_c)
print("")
print("printing the derivative of the polynomial with exponents and coefficients")
print(np.poly1d(d_c))
print("")
print("printing the derivative of the polynomial without reversing the coefficient array after derivation")
print(np.poly1d(P.polyder(c)))
print("")输出:
the array of coefficients for the polynomial
(1, 1, 1, 1)
polynomial with coefficients and exponents
3 2
1 x + 1 x + 1 x + 1
array of coefficients of derivative of polynomial: lowest order coming first in the array
[ 1. 2. 3.]
reversing the array of coefficients for the derivative of the polynomial
[ 3. 2. 1.]
printing the derivative of the polynomial with exponents and coefficients
2
3 x + 2 x + 1
printing the derivative of the polynomial without reversing the coefficient array after derivation
2
1 x + 2 x + 3发布于 2018-03-17 17:47:16
对从deriv返回的对象使用np.poly1d方法
import numpy as np
p = np.poly1d([1, 3, 1, 0, 4])
print(p)
print(p.deriv(1))有关可用方法的完整列表,请参见医生们。
https://stackoverflow.com/questions/49331545
复制相似问题