我需要将函数拟合到数据数组中,并获得该函数方程的最优系数。我从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