title: calculate histogram peaks in python
body: <p>In Python, how do I calcuate the peaks of a histogram?  </p>
  
  <p>I tried this:</p>
  
  <pre><code>import numpy as np
  from scipy.signal import argrelextrema
  
  data = [0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 1, 2, 3, 4,
  
          5, 6, 7, 8, 9, 5, 6, 7, 8, 9, 5, 6, 7, 8, 9,
  
          12,
  
          15, 16, 17, 18, 19, 15, 16, 17, 18, 
  
          19, 20, 21, 22, 23, 24,]
  
  h = np.histogram(data, bins=[0, 5, 10, 15, 20, 25])
  hData = h[0]
  peaks = argrelextrema(hData, np.greater)
  </code></pre>
  
  <p>But the result was:</p>
  
  <pre><code>(array([3]),)
  </code></pre>
  
  <p>I'd expect it to find the peaks in bin 0 and bin 3. </p>
  
  <p>Note that the peaks span more than 1 bin.  I don't want it to consider the peaks that span more than 1 column as additional peak.</p>
  
  <p>I'm open to another way to get the peaks.</p>
  
  <p>Note:</p>
  
  <pre><code>&gt;&gt;&gt; h[0]
  array([19, 15,  1, 10,  5])
  &gt;&gt;&gt; 
  </code></pre>