Probability and Arrays
Learn how to calculate probabilities using programming.
We'll cover the following...
Introduction to probability
Probability is a critical concept of discrete mathematical operations. Like the set theory concepts, probability concepts are also applied diversely in computer science and the programming world.
Before looking at code, let’s discuss what probability means. Consider heads and tails. If we flip a coin, there’s a 50-50 probability of getting heads or tails. But the equation changes when we throw a dice up in the air.
What’s the probability of getting a 2 when we throw a dice? The favorable outcome is 1 because a dice has one 2 on it. On the contrary, the possible product is 6. Although a dice is a three-dimensional object, we can write the six elements in a dataset because there are six sides to a dice. We can create and initialize an array with the six integers and calculate all the probabilities.
The probability theory is not limited to dice; we can explore a range of massive data and calculate all types of probabilities.
Python implementation
Below is the basic probability definition by Laplace:
...