python适合多变量
我想根据1个参数拟合2个参数的函数 代码示例:python适合多变量,python,scipy,Python,Scipy,我想根据1个参数拟合2个参数的函数 代码示例: import numpy from scipy.optimize import curve_fit data=numpy.array([[[0, 1], 1, 0.1], [[0, 2], 2.1, 0.1], [[1,1], 2.9,0.1]], dtype=object) def model(x, a): res=[] for xx in x: x0=x[0] x1=x[1] re
import numpy
from scipy.optimize import curve_fit
data=numpy.array([[[0, 1], 1, 0.1], [[0, 2], 2.1, 0.1], [[1,1], 2.9,0.1]], dtype=object)
def model(x, a):
res=[]
for xx in x:
x0=x[0]
x1=x[1]
res.append(a*x1+x0)
return numpy.array(res)
parameter, covariance = curve_fit(model, data[:, 0], data[:, 1], p0=1, sigma=data[:, 2], absolute_sigma = True, method = 'lm')
但是,这会产生以下错误:
ValueError: setting an array element with a sequence.
如何修复错误