Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7815063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:23:44+00:00 2026-06-02T05:23:44+00:00

I am writing a program in Python that will fit Gaussian and Lorentzian shapes

  • 0

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 changed to using optimize.curve_fit after having difficulties in retrieving the errors in the optimized parameters from the covariance matrix.

I have defined a function to fit a sum of Gaussian and Lorentzian:

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

where p is an array of the initial guesses at the fit parameters. Here is the instance where it is called using curve_fit:

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

At the moment numg (the number of Gaussian shapes) is a global variable. Is there’s any way that it can be incorporated into curve_fit as an extra argument instead, as can be done with leastsq?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T05:23:45+00:00Added an answer on June 2, 2026 at 5:23 am

    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
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a program in Python that will act as a server and
I'm writing a python program that will spawn a subprocess to basically clone a
I just started learning Python... I am writing a simple program that will take
I'm writing a Python program that will use Twisted to connect to a TCP
I am writing a basic program in Python that prompts the user to enter
I am writing a python program that lauches a subprocess (using Popen). I am
I am writing a program in Python, and I realized that a problem I
I'm writing a program that will parse an Apache log file periodically to log
I'm writing a personal wiki-style program in Python that stores text files in a
I am writing a native function that will return multiple Python objects PyObject *V

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.