Binomial Distribution in NumPy Last Updated : 23 Apr, 2025 Comments Improve Suggest changes Like Article Like Report The Binomial Distribution is a fundamental concept in probability and statistics. It models the number of successes in a fixed number of independent trials where each trial has only two possible outcomes: success or failure. This distribution is widely used in scenarios like coin flips, quality control and surveys. The numpy.random.binomial() method generates random numbers that follow a Binomial Distribution. It has three key parameters:n : The number of trials (e.g., number of coin flips).p : The probability of success in each trial (e.g., probability of getting heads in a coin flip).size : The shape of the returned array.Syntax:numpy.random.binomial(n, p, size=None)Example 1: Generate a Single Random NumberTo generate a single random number from a Binomial Distribution with n=10 trials and p=0.5 probability of success: Python import numpy as np random_number = np.random.binomial(n=10, p=0.5) print(random_number) Output:3Example 2: Generate an Array of Random NumbersTo generate multiple random numbers: Python random_numbers = np.random.binomial(n=10, p=0.5, size=5) print(random_numbers) Output:[6 5 4 3 5]Visualizing the Binomial DistributionVisualizing the generated numbers helps in understanding their behavior. Below is an example of plotting a histogram of random numbers generated using numpy.random.binomial. Python import numpy as np import matplotlib.pyplot as plt n = 10 p = 0.5 size = 1000 data = np.random.binomial(n=n, p=p, size=size) plt.hist(data, bins=np.arange(-0.5, n+1.5, 1), density=True, edgecolor='black', alpha=0.7, label='Histogram') x = np.arange(0, n+1) pmf = binom.pmf(x, n=n, p=p) plt.scatter(x, pmf, color='red', label='Theoretical PMF') plt.vlines(x, 0, pmf, colors='red', linestyles='dashed') plt.title("Binomial Distribution (n=10, p=0.5)") plt.xlabel("Number of Successes") plt.ylabel("Probability") plt.legend() plt.grid(True) plt.show() Output: Binomial DistributionThe image shows a Binomial Distribution with 10 trials (n=10) and a 50% success rate (p=0.5). The blue bars represent simulated data and the red dots show the expected probabilities. The distribution is symmetric, centered around 5 successes. Comment More infoAdvertise with us Next Article Binomial Distribution in NumPy A ayushimalm50 Follow Improve Article Tags : Python Numpy python Practice Tags : pythonpython Similar Reads Python - Binomial Distribution Binomial distribution is a probability distribution that summarises the likelihood that a variable will take one of two independent values under a given set of parameters. The distribution is obtained by performing a number of Bernoulli trials. A Bernoulli trial is assumed to meet each of these crit 4 min read Binomial Distribution in R Programming Binomial distribution in R is a probability distribution used in statistics. The binomial distribution is a discrete distribution and has only two outcomes i.e. success or failure. All its trials are independent, the probability of success remains the same and the previous outcome does not affect th 3 min read Chi-Square Distribution in NumPy The Chi-Square Distribution is used in statistics when we add up the squares of independent random numbers that follow a standard normal distribution. It is used in hypothesis testing to check whether observed data fits a particular distribution or not. In Python you can use the numpy.random.chisqua 2 min read Normal Distribution in NumPy The Normal Distribution also known as the Gaussian Distribution is one of the most important distributions in statistics and data science. It is widely used to model real-world phenomena such as IQ scores, heart rates, test results and many other naturally occurring events.numpy.random.normal() Meth 2 min read Poisson Distribution in NumPy 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( 2 min read Like