我试图在python中将一个简单的函数拟合到两个独立数据数组中.我知道我需要将我的自变量的数据聚集到一个数组中,但是当我尝试进行拟合时,我传递变量的方式似乎仍然存在问题.(之前有几篇与此相关的文章,但它们没有太多帮助.)
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
def fitFunc(x_3d, a, b, c, d):
return a + b*x_3d[0,:] + c*x_3d[1,:] + d*x_3d[0,:]*x_3d[1,:]
x_3d = np.array([[1,2,3],[4,5,6]])
p0 = [5.11, 3.9, 5.3, 2]
fitParams, fitCovariances = curve_fit(fitFunc, x_3d[:2,:], x_3d[2,:], p0)
print ' fit coefficients:\n', fitParams
Run Code Online (Sandbox Code Playgroud)
我得到的错误,
raise TypeError('Improper input: N=%s must not exceed M=%s' % (n, m))
TypeError: Improper input: N=4 must not exceed M=3
Run Code Online (Sandbox Code Playgroud)
什么是M长度?是N长度p0?我在这做错了什么?