python中curve fit_在python中拟合多变量curve_fit
我試圖將一個簡單的函數適用于
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中curve fit_在python中拟合多变量curve_fit的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 卢伟冰:Redmi Note 12 Tu
- 下一篇: 刹车失灵?福特全球召回近130万辆汽车