Open In App

Poisson Distribution in NumPy

Last Updated : 15 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

The Poisson Distribution model the number of times an event happens within a fixed time or space when we know the average number of occurrences. It is used for events that occur independently such as customer arrivals at a store, Website clicks where events happen independently.

numpy.random.poisson() Method

In Python'sNumPylibrary we can generate random numbers following a Poisson Distribution using the numpy.random.poisson() method. It has two key parameters:

  • lam : The average number of events (λ) expected to occur in the interval.
  • size : The shape of the returned array.

Syntax:

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

Example 1: Generate a Single Random Number

To generate a single random number from a Poisson Distribution with an average rate of λ = 5:

Python
import numpy as np

random_number = np.random.poisson(lam=5)
print(random_number)

Output :

5

Example 2: Generate an Array of Random Numbers

To generate multiple random numbers:

Python
random_numbers = np.random.poisson(lam=5, size=5)
print(random_numbers)

Output :

[13 6 4 4 10]

Visualizing the Poisson Distribution

To understand the distribution better we can visualize the generated numbers. Here is an example of plotting a histogram of random numbers generated using numpy.random.poisson.

Python
import numpy as np
from numpy import random
import matplotlib.pyplot as plt
import seaborn as sns

lam = 2  
size = 1000  

data = random.poisson(lam=lam, size=size)

sns.displot(data, kde=False, bins=np.arange(-0.5, max(data)+1.5, 1), color='skyblue', edgecolor='black')

plt.title(f"Poisson Distribution (λ={lam})")
plt.xlabel("Number of Events")
plt.ylabel("Frequency")
plt.grid(True)

plt.show()

Output:

poisson-distribution
Poisson Distribution

The image shows a Poisson Distribution with λ=2 displaying the frequency of events. The histogram represents simulated data highlighting the peak at 0 and 1 events, with frequencies decreasing as the number of events increases.



Practice Tags :

Similar Reads

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy