我需要將函數擬合到數據數組中,並獲得該函數方程的最優係數。我從scipy庫使用curve_fit方法。它基於最小二乘法。Python scipy:**或pow():'list'和'list'不支持的操作數類型
import numpy as np
from scipy.optimize import curve_fit
#This is my function from which i need to get optimal coefficients 'a' and 'b'
def func(x, a, b):
return a*x**(b*x)
#the arrays of input data
x = [1,2,3,4,5]
y =[6,7,8,9,10]
#default (guess) coefficients
p0 = [1, 1]
popt, pcov = curve_fit(func, x, y, p0)
print popt
它返回以下錯誤
TypeError: unsupported operand type(s) for ** or pow(): 'list' and 'list'
但是當我用其他的,更簡單的功能,沒有權力運作它的工作原理
def func(x, a, b):
return a*x + b
必須努力bulid號碼整個輸入數據陣列的功率
怎麼辦?請幫助...
你究竟如何將數組放入另一個數組的功率? – 2012-02-06 06:12:18