Py-ser
Py-ser

Reputation: 2098

Drawing random numbers returns only integers

I am probably missing an important point on statistics or numpy/scipy. I want to generate random numbers with poissonian statistics, whose expected value is a decimal less than 1, e.g., lambda = 0.6. When I pythonize this:

>>> from scipy.stats import poisson
>>> import numpy as np
>>> lambda = 0.6
>>> poisson.rvs(lambda, size=10)
>>> print r
[2 2 0 0 0 2 1 0 0 2 ]

Trying

>>> r = np.real(poisson.rvs(lambda, size=10))

Gives the same result.

Why there are no decimals between 0 and 1 ?

Upvotes: 0

Views: 1650

Answers (2)

lejlot
lejlot

Reputation: 66805

Poisson is not continuous probability distribution, so this is expected behavior

http://en.wikipedia.org/wiki/Poisson_distribution

Furthermore do not call your variables lambda, this is an important Python operator

Upvotes: 2

Ffisegydd
Ffisegydd

Reputation: 53678

The Poisson distribution is a discrete probability distribution, meaning that you can only get integer variates, not decimal.

Note: this doesn't mean the probability P associated with a particular variate is integer, that can be a decimal, just the individual variates themselves must be integer.

Upvotes: 7

Related Questions