bundles / numpy 2.4.4 / numpy / random / RandomState / multinomial
cython_function_or_method
numpy.random:RandomState.multinomial
Signature
def multinomial ( n , pvals , size = None ) Summary
Draw samples from a multinomial distribution.
Extended Summary
The multinomial distribution is a multivariate generalization of the binomial distribution. Take an experiment with one of p possible outcomes. An example of such an experiment is throwing a dice, where the outcome can be 1 through 6. Each sample drawn from the distribution represents n such experiments. Its values, X_i = [X_0, X_1, ..., X_p], represent the number of times the outcome was i.
Parameters
n: intNumber of experiments.
pvals: sequence of floats, length pProbabilities of each of the
pdifferent outcomes. These must sum to 1 (however, the last element is always assumed to account for the remaining probability, as long assum(pvals[:-1]) <= 1).size: int or tuple of ints, optionalOutput shape. If the given shape is, e.g.,
(m, n, k), thenm * n * ksamples are drawn. Default is None, in which case a single value is returned.
Returns
out: ndarrayThe drawn samples, of shape size, if that was provided. If not, the shape is
(N,).In other words, each entry
out[i,j,...,:]is an N-dimensional value drawn from the distribution.
Examples
Throw a dice 20 times:np.random.multinomial(20, [1/6.]*6, size=1)
✗np.random.multinomial(20, [1/6.]*6, size=2)
✗np.random.multinomial(100, [1/7.]*5 + [2/7.])
✗np.random.multinomial(100, [1.0 / 3, 2.0 / 3]) # RIGHT
✗np.random.multinomial(100, [1.0, 2.0]) # WRONG
✓See also
- random.Generator.multinomial
which should be used for new code.
Aliases
-
numpy.random.multinomial -
numpy.random.RandomState.multinomial