Python Specials #4 Bernoulli Distribution

Опубликовано: 17 Июль 2026
на канале: Coder & Maker
390
4

The Bernoulli distribution models the probability of a binary outcome, where there are only two possible outcomes (often referred to as "success" and "failure"). The distribution is parameterized by a single probability value, p, which represents the probability of success. For example, in the code example, p = 0.3 means that the probability of success is 0.3. The distribution takes on the value 1 (for success) with probability p, and the value 0 (for failure) with probability 1-p.

In the code example, we create a bernoulli object from the scipy.stats module with the given probability of success, and then use its pmf method to calculate the probability of success (getting a 1), and its rvs method to generate a sample of 10 outcomes from the distribution. We also plot the probability mass function (PMF) of the distribution using matplotlib.

Thanks for watching. For more videos and to support us, you can subscribe and follow our channel. Good luck...

All Coder & Maker videos :    • ALL VIDEOS  
More Python Special videos:    • Python Specials  
More Python Examples videos:    / playlist  
list=PLN6LC3AB64ggeDF1_fR-77gdlNrtz-8VQ
Python Basics Videos :    • Python Basics  
Python Turtle Graphics Module:    • Python Turtle  Graphics  
Python Matplotlib Module Tutorials:    • Python Matplotlib Module  
Python Numpy Module Tutorials:    • Python Numpy Module  
Python Random Module Tutorials:    • Python Random Module  
Python Thonny Graphics Tutorials:    • Python Turtle Tutorials  


Download Thonny Ide: https://thonny.org