title: Fitting a multi-peak function to a DataSet using LMFIT
body: <p>I'm trying to make a multi-lorentzian fitting using the LMFIT library,
  but it's not working and I even understand that the syntax of what I 
  made is completelly wrong, but I don't have any new ideas.</p>
  
  <p>My problem is this: I have a very long spectra with multiple sets of
  peaks, but the number of peaks is not constant  in these sets, so
  sometimes I will have just 1 peak, but sometimes I might have 8 
  or even 20.</p>
  
  <pre><code>#function definition:
  
  def Lorentzian(x, amp, cen, wid, n):
      f = 0
      for i in range( int(n) ):
          "lorentzian function: wid = half-width at half-max"
          f += (amp[i]/(1 + ((x-cen[i])/wid[i])**2))
      return f
  
  #library import and model definition:
  
  import lmfit as lf
  
  lmodel = lf.Model(Lorentzian)
  
  #The initial parameters for the model:
  peaks_in_interval = np.array([2378, 2493, 2525, 2630, 2769])
  
  number_of_peaks = len(peaks_in_interval)         
  amplitude = width = np.zeros( number_of_peaks ) + 1
  center = x[peaks_in_interval]
  
  params = lmodel.make_params(x = x, amp = amplitude, cen = center, wid = width, n = number_of_peaks)
  
  #This is the line that doesn't work:                        
  result = lmodel.fit( y, params, x = x )
  </code></pre>
  
  <p>I've started trying to make a generic function that returns a 
  multi-Lorentzian, but I'm struggling in how to make that work...</p>
  
  <p>I'm also sending the data for x, y arrays.</p>
  
  <p><a href="http://www.mediafire.com/?81ct5z5e5ad65" rel="nofollow noreferrer">DataSet for x  and y</a></p>
  
  <p><a href="https://i.stack.imgur.com/Mf7Zg.png" rel="nofollow noreferrer">This is what the DataSet of x and y looks like.</a></p>