【发布时间】:2014-01-13 04:40:42
【问题描述】:
我正在尝试为 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
我读到的错误,
raise TypeError('Improper input: N=%s must not exceed M=%s' % (n, m))
TypeError: Improper input: N=4 must not exceed M=3
M 的长度是多少? N 是p0 的长度吗?我在这里做错了什么?
【问题讨论】:
标签: python scipy curve-fitting