title: Matplotlib: How to convert a histogram to a discrete probability mass function?
body: <p>I have a question regarding the hist() function with matplotlib.</p>
  
  <p>I am writing a code to plot a histogram of data who's value varies from 0 to 1. For example:</p>
  
  <pre><code>values = [0.21, 0.51, 0.41, 0.21, 0.81, 0.99]
  
  bins = np.arange(0, 1.1, 0.1)
  a, b, c = plt.hist(values, bins=bins, normed=0)
  plt.show()
  </code></pre>
  
  <p>The code above generates a correct histogram (I could not post an image since I do not have enough reputation). In terms of frequencies, it looks like:</p>
  
  <pre><code>[0 0 2 0 1 1 0 0 1 1]
  </code></pre>
  
  <p>I would like to convert this output to a discrete probability mass function, i.e. for the above example, I would like to get a following frequency values:</p>
  
  <pre><code>[ 0.  0.  0.333333333  0.  0.166666667  0.166666667  0.  0.  0.166666667  0.166666667 ] # each item in the previous array divided by 6)
  </code></pre>
  
  <p>I thought I simply need to change the parameter in the hist() function to 'normed=1'. However, I get the following histogram frequencies:</p>
  
  <pre><code>[ 0.  0.  3.33333333  0.  1.66666667  1.66666667  0.  0.  1.66666667  1.66666667 ]
  </code></pre>
  
  <p>This is not what I expect and I don't know how to get the discrete probability mass function who's sum should be 1.0. A similar question was asked in the following link (<a href="https://stackoverflow.com/questions/5498008/pylab-histdata-normed-1-normalization-seems-to-work-incorrect">link to the question</a>), but I do not think the question was resolved.</p>
  
  <p>I appreciate for your help in advance.</p>