Skip to content

Term Entry numpy.random.poisson() #7304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions content/numpy/concepts/random-module/terms/poisson/poisson.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
---
Title: '.poisson()'
Description: 'Returns random integers from a Poisson distribution.'
Subjects:
- 'Data Science'
- 'Data Visualization'
Tags:
- 'Data Distributions'
- 'NumPy'
- 'Probability'
- 'Random'
CatalogContent:
- 'learn-python-3'
- 'paths/data-science-foundations'
---

NumPy’s `random` module includes the **`.poisson()`** function, which draws random samples from a Poisson distribution. This distribution models the probability of observing `k` events in a fixed time interval, given they occur at a constant average rate $`\lambda`$ and independent of the time since the last event.

**The Poisson distribution**:

$$f\left(k;\lambda\right) = \frac{\lambda^k e^{-\lambda}}{k!}$$

## Syntax

```pseudo
numpy.random.poisson(lam=1.0, size=None)
```

**Parameters:**

- `lam` (float, or array_like of floats): The expected number of events occurring over a fixed-time period. Must be `>=0`.
- `size` (int, or tuple of ints, optional): Specifies the output shape. For example, `(3, 4)` produces a _3×4_ array. If `None`, a single sample is returned if `lam` is scalar; otherwise, `np.array(lam).size` samples are drawn.

**Return value:**

- `out` (ndarray or scalar): Samples drawn from the Poisson distribution with the specified parameters.

## Example 1

This example draws 10 samples from a Poisson distribution with `lam=5`:

```py
import numpy as np

# Generate 10 random samples from a Poisson distribution with λ = 5
results = np.random.poisson(5, 10)

# Print the samples
print(results)
```

This code outputs something similar to this:

```shell
[ 7 5 13 5 4 3 2 8 3 4]
```

## Example 2

This example generates a _3×4_ matrix of random integers from a Poisson distribution with `λ = 5`:

```py
import numpy as np

# Generate a 3x4 array of Poisson samples with λ = 5
results = np.random.poisson(5, (3, 4))

print(results)
```

This code produces an output similar to this:

```shell
[[4 4 4 7]
[1 8 3 4]
[3 4 8 5]]
```

> **Note:** The method produces random results so outcomes will vary.

## Codebyte Example

This codebyte example generates 10 Poisson-distributed random samples using a lambda value of `5` and prints the result:

```codebyte/python
import numpy as np

# Set lambda value
lam = 5

# Set sample size
size = 10

# Generate samples
results = np.random.poisson(lam, size)

# Print the samples
print(results)
```