1

Let's say I have a list of random variables, and I use the histogram function like this:

import numpy as np
x = [np.random.randn() for i in range(2**10)]
vals, bin_edges = np.histogram(x, 100)

1) How do I efficiently normalize this histogram to become a list representations of a probability mass function?

2) How do I map from this probability mass function to a new list in such a way that I end up with a list where the value at i corresponds to the probability of observing x[i]?

L1meta
  • 363
  • 4
  • 14
  • Technically the probability of observing `x[i]` is zero. Or -- well, very very small (since we're talking about floating point numbers and not actual real numbers). Do you mean the probability of observing a value in the same bin as `x[i]`? – senderle Oct 10 '14 at 16:42
  • My bad, this is of course what I meant. – L1meta Oct 10 '14 at 19:02
  • I think this is a duplicate: http://stackoverflow.com/questions/11750276/matplotlib-how-to-convert-a-histogram-to-a-discrete-probability-mass-function – farenorth Oct 10 '14 at 19:46

0 Answers0