code: def find_N_peaks(array, N=4, max_iterations=100, rec_max_iterations=3, recursion=1):
      
  
      if recursion<0: return None
  
      # get an initial guess as to the baseline
      ymin = min(array)
      ymax = max(array)
  
      for n in range(max_iterations):
  
          # bisect the range to estimate the baseline
          y1 = (ymin+ymax)/2.0
  
          # now see how many peaks this finds. p could have 40 for all we know
          p, s, i = find_peaks(array, y1, True)
  
          # now loop over the subarrays and make sure there aren't two peaks in any of them
          for n in range(len(i)):
              # search the subarray for two peaks, iterating 3 times (75% selectivity)
              p2 = find_N_peaks(s[n], 2, rec_max_iterations, rec_max_iterations=rec_max_iterations, recursion=recursion-1)
  
              # if we found a double-peak
              if not p2 is None:
                  # push these non-duplicate values into the master array
                  for x in p2:
                      # if this point is not already in p, push it on
                      if not x in p: p.append(x+i[n]) # don't forget the offset, since subarrays start at 0
  
  
          # if we nailed it, finish up
          if len(p) == N: return p
  
          # if we have too many peaks, we need to increase the baseline
          if len(p) > N: ymin = y1
  
          # too few? decrease the baseline
          else:          ymax = y1
  
      return None
docs: This will run the find_peaks algorythm, adjusting the baseline until exactly N peaks are found.