mercredi 13 décembre 2017

Weird behavior of random numbers in Python

I stumbled upon some peculiar behavior of random numbers in Python , specifically I use the module numpy.random.

Consider the following expression:

n = 50
N = 1000
np.histogram(np.sum(np.random.randint(0, 2, size=(n, N)), axis=0), bins=n+1)[0]

In the limit of large N I would expect a binomial distribution (for the interested reader, this simulates the Ehrenfest model) and for large n a normal distribution. A typical output however, looks like this:

array([
1, 0, 0, 1, 0, 2, 0, 1, 0, 15, 0,
12, 0, 18, 0, 39, 0, 64, 0, 62, 0, 109,
0, 97, 0, 107, 0, 114, 0, 102, 0, 92, 0,
55, 0, 46, 0, 35, 0, 10, 0, 9, 0, 4,
0, 0, 0, 3, 0, 1, 1
])

With the statement from above, I can't explain the occurrence of the zeros in the histogram - am I missing something obvious here?




Aucun commentaire:

Enregistrer un commentaire