How do you generate random numbers in a poisson distribution in python?

random.poisson[lam=1.0, size=None]#

Draw samples from a Poisson distribution.

The Poisson distribution is the limit of the binomial distribution for large N.

Note

New code should use the poisson method of a default_rng[] instance instead; please see the Quick Start.

Parameterslamfloat or array_like of floats

Expected number of events occurring in a fixed-time interval, must be >= 0. A sequence must be broadcastable over the requested size.

sizeint or tuple of ints, optional

Output shape. If the given shape is, e.g., [m, n, k], then m * n * k samples are drawn. If size is None [default], a single value is returned if lam is a scalar. Otherwise, np.array[lam].size samples are drawn.

Returnsoutndarray or scalar

Drawn samples from the parameterized Poisson distribution.

Notes

The Poisson distribution

\[f[k; \lambda]=\frac{\lambda^k e^{-\lambda}}{k!}\]

For events with an expected separation \[\lambda\] the Poisson distribution \[f[k; \lambda]\] describes the probability of \[k\] events occurring within the observed interval \[\lambda\].

Because the output is limited to the range of the C int64 type, a ValueError is raised when lam is within 10 sigma of the maximum representable value.

References

1

Weisstein, Eric W. “Poisson Distribution.” From MathWorld–A Wolfram Web Resource. //mathworld.wolfram.com/PoissonDistribution.html

2

Wikipedia, “Poisson distribution”, //en.wikipedia.org/wiki/Poisson_distribution

Examples

Draw samples from the distribution:

>>> import numpy as np
>>> s = np.random.poisson[5, 10000]

Display histogram of the sample:

>>> import matplotlib.pyplot as plt
>>> count, bins, ignored = plt.hist[s, 14, density=True]
>>> plt.show[]

Draw each 100 values for lambda 100 and 500:

>>> s = np.random.poisson[lam=[100., 500.], size=[100, 2]]

method

random.Generator.poisson[lam=1.0, size=None]#

Draw samples from a Poisson distribution.

The Poisson distribution is the limit of the binomial distribution for large N.

Parameterslamfloat or array_like of floats

Expected number of events occurring in a fixed-time interval, must be >= 0. A sequence must be broadcastable over the requested size.

sizeint or tuple of ints, optional

Output shape. If the given shape is, e.g., [m, n, k], then m * n * k samples are drawn. If size is None [default], a single value is returned if lam is a scalar. Otherwise, np.array[lam].size samples are drawn.

Returns outndarray or scalar

Drawn samples from the parameterized Poisson distribution.

Notes

The Poisson distribution

\[f[k; \lambda]=\frac{\lambda^k e^{-\lambda}}{k!}\]

For events with an expected separation \[\lambda\] the Poisson distribution \[f[k; \lambda]\] describes the probability of \[k\] events occurring within the observed interval \[\lambda\].

Because the output is limited to the range of the C int64 type, a ValueError is raised when lam is within 10 sigma of the maximum representable value.

References

1

Weisstein, Eric W. “Poisson Distribution.” From MathWorld–A Wolfram Web Resource. //mathworld.wolfram.com/PoissonDistribution.html

2

Wikipedia, “Poisson distribution”, //en.wikipedia.org/wiki/Poisson_distribution

Examples

Draw samples from the distribution:

>>> import numpy as np
>>> rng = np.random.default_rng[]
>>> s = rng.poisson[5, 10000]

Display histogram of the sample:

>>> import matplotlib.pyplot as plt
>>> count, bins, ignored = plt.hist[s, 14, density=True]
>>> plt.show[]

Draw each 100 values for lambda 100 and 500:

>>> s = rng.poisson[lam=[100., 500.], size=[100, 2]]

How do you generate a random number in a Poisson distribution?

r = poissrnd[ lambda ] generates random numbers from the Poisson distribution specified by the rate parameter lambda . lambda can be a scalar, vector, matrix, or multidimensional array.

How do you sample a Poisson distribution in Python?

The Poisson distribution describes the probability of obtaining k successes during a given time interval. If a random variable X follows a Poisson distribution, then the probability that X = k successes can be found by the following formula: P[X=k] = λk * e λ / k!

What is the random variable in Poisson distribution?

A random variable is said to have a Poisson distribution with the parameter λ, where “λ” is considered as an expected value of the Poisson distribution. The expected value of the Poisson distribution is given as follows: E[x] = μ = d[eλ[t-1]]/dt, at t=1.

How do you make a Poisson random variable from uniform?

then N is a random variable distributed according to a Poisson distribution. Generating exponential variates is easily done by using the inverse method. For a uniform random variable U on the unit interval [0,1], the transformation E= -\log[U]/\lambda gives an exponential random variable with mean 1/\lambda.

Chủ Đề