Numpy Random Multinomial
NumPy Random Multinomial is a function in NumPy that generates a multinomial distribution.
In this article, we will discuss what a NumPy Random Multinomial Distribution is, its properties, and how to utilize it in NumPy.
In Numpy random multinomial, multinomial probabilities are generalizations of binomial distributions.
A multinomial distribution is a probability distribution that describes the probabilities of a set of possible outcomes in a series of independent trials.
A multinomial scenario explains the results of multiple variables, in contrast to a binomial scenario which can only have two variables.
For example: The kind of blood in a population, the result of a dice roll.
numpy.random.multinomial(n, pvals, size=None)
|n||The number of possible results that can happen (for example, six possibilities for a dice roll).|
|pvals||This is a list of probabilities of results (for example. [1/6, 1/6, 1/6, 1/6, 1/6, 1/6, 1/6, 1/6, 1/6] for a dice roll).|
|size||Determines the array’s shape.|
Let’s look examples below to understand how the NumPy Random Multinomial function works.
Make a sample dice roll by drawing out the following:
- The n parameter is set to 6, which means the dice will be rolled 6 times.
- The pvals parameter is set to a list of six equal probabilities, where each probability is 1/6, representing the probability of rolling each of the six faces of the dice.
- The random.multinomial() function generates a random sample of outcomes from a multinomial distribution, where each outcome represents the number of times each face of the dice was rolled in the given number of trials.
- The output of the function is an array of counts, where each element of the array represents the number of times each face of the dice was rolled in the 6 trials.
- The output of the code will be a random array of 6 integers, where each integer represents the count of times the corresponding face of the dice was rolled in the 6 trials.
- The sum of all the counts in the output array will be equal to the number of trials, which is 6 in this case.
You can draw out a sample of a coin flip as follows: