1 回答

TA貢獻1824條經(jīng)驗 獲得超6個贊
如果我想到了,您可能想創(chuàng)建一個多項式表示形式作為 lambda 函數(shù)。所以讓我建議替代函數(shù):
import numpy as np
def alternative_create_F(coeffs):
Y = lambda x: sum([item*(x**iter) for iter, item in enumerate(coeffs)])
return Y
coeffs = np.array([8, -3, 4]) # first is the free coeff second is x coeff and so on
idk = alternative_create_F(coeffs)
print(idk(3))
print(idk(6))
請注意該number變量是不相關(guān)的,因為您可以從len(coeffs).
現(xiàn)在 lambda 函數(shù)保存多項式的表示 -
coeffs[0] + coeffs[1]*x + coeffs[2]*x^2
要調(diào)用 lambda 函數(shù),請將其作為具有所需 x 值的函數(shù)來調(diào)用。從我的示例收到的輸出:
35 ===> 8+(-3)*3+4*3^2 = 8-9+36 = 35
134 ===> 8+(-3)*6+4*6^2 = 8-18+144 = 134
希望你覺得它有用
添加回答
舉報