4

I have a number X of integers (very large) and a probability p with which I want to draw a sample s (a number) from X following a Poisson distribution. For example, if X = 10^8 and p=0.05, I expect s to be the number of heads we get.

I was able to easily do this with random.binomial as:

s=np.random.binomial(n=X, p=p)

How can I apply the same idea using random.poisson?

martineau
  • 119,623
  • 25
  • 170
  • 301
Joana
  • 49
  • 1
  • 3

2 Answers2

2

Just multiply p and X:

np.random.poisson(10**8 * 0.05)

The probability to get more than 10**8 is numerically zero.

Professor @pjs emphasizes that we are combining probability and number into a rate which is the parameter of the Poisson process.

Further worth mentioning that for such a large number you'll find the pmf's of Binomial and Poisson very similar to each other and also (using probability function or "cdf" as engineers call it) to a Gaussian.

Paul Panzer
  • 51,835
  • 3
  • 54
  • 99
-2

https://docs.scipy.org/doc/numpy-1.14.0/reference/generated/numpy.random.poisson.html

 import numpy as np
 s = np.random.poisson(size=n, lam=p)
Fredz0r
  • 522
  • 5
  • 11