Passing additional arguments using scipy.optimize.curve_fit?

后端 未结 1 1747
南旧
南旧 2020-12-17 14:49

I am writing a program in Python that will fit Gaussian and Lorentzian shapes to some given resonance data. I originally began using scipy.optimize.leastsq but

1条回答
  •  囚心锁ツ
    2020-12-17 15:01

    The great thing about python is that you can define functions that return other functions, try currying:

    def make_mix(numg): 
        def mix(x, *p): 
            ng = numg
            p1 = p[:3*ng]
            p2 = p[3*ng:]
            a = sumarray(gaussian(x,p1),lorentzian(x,p2))
            return a
        return mix
    

    and then

    leastsq, covar = opt.curve_fit(make_mix(numg),energy,intensity,inputtot)
    

    0 讨论(0)
提交回复
热议问题