def find_N_peaks(array, N=<NUM_LIT:4>, max_iterations=<NUM_LIT:100>, rec_max_iterations=<NUM_LIT:3>, recursion=<NUM_LIT:1>):
if recursion<<NUM_LIT:0>: return None<EOL>ymin = min(array)<EOL>ymax = max(array)<EOL>for n in range(max_iterations):<EOL><INDENT>y1 = (ymin+ymax)/<NUM_LIT><EOL>p, s, i = find_peaks(array, y1, True)<EOL>for n in range(len(i)):<EOL><INDENT>p2 = find_N_peaks(s[n], <NUM_LIT:2>, rec_max_iterations, rec_max_iterations=rec_max_iterations, recursion=recursion-<NUM_LIT:1>)<EOL>if not p2 is None:<EOL><INDENT>for x in p2:<EOL><INDENT>if not x in p: p.append(x+i[n]) <EOL><DEDENT><DEDENT><DEDENT>if len(p) == N: return p<EOL>if len(p) > N: ymin = y1<EOL>else:          ymax = y1<EOL><DEDENT>return None<EOL>
This will run the find_peaks algorythm, adjusting the baseline until exactly N peaks are found.