Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python适合多变量_Python_Scipy - Fatal编程技术网

python适合多变量

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

我想根据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]
        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.
如何修复错误