Python- obtain maximum value in an interval
<p>I have a .CSV file (a list) that contains 43142 rows and 2 columns.</p>

<p>When plotting the list's values x vs y:</p>

<pre><code>    import numpy as np
    import matplotlib.pyplot as plt

    filename=np.genfromtxt(list.CSV,delimiter=',')
    plt.plot(filename[:,0],filename[:,1])
</code></pre>

<p>I get a graph which has multiple maxima values and looks like this:
<a href="http://i.stack.imgur.com/4XDpq.png" rel="nofollow">x vs y values of list.CSV</a></p>

<p>What i want to do is, given an aproximate interval in the x values in which the peaks are positioned, find the maximum values and the corresponding indices on the list.</p>

<p><em>e.g</em> if there's a maximum <strong>y</strong> value in the interval <strong>x=(2720,2730)</strong> (refer to figure <a href="http://i.stack.imgur.com/ZNJwZ.png" rel="nofollow">2</a>), i want to find the exact index in which the value is maximum.</p>

<p>If you have a range <code>xmin &lt; x &lt; xmax</code> then this should work (taking <code>x=filename[:,0]</code> and <code>y=filename[:,1]</code>) :</p>

<pre><code>idx = np.where(y==np.max(y[(x&gt;xmin)&amp;(x&lt;xmax)]))[0][0]
</code></pre>

<p>This will return a single index corresponding to the maximum y value in the given range.</p>

python python-2.7 numpy argmax