dask 2021.10.0

ParametersReturns
multinomial(self, n, pvals, size=None, chunks='auto', **kwargs)

This docstring was copied from numpy.random.mtrand.RandomState.multinomial.

Some inconsistencies with the Dask version may exist.

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 .

note

New code should use the multinomial method of a default_rng() instance instead; please see the :None:ref:`random-quick-start`.

Parameters

n : int

Number of experiments.

pvals : sequence of floats, length p

Probabilities of each of the p different outcomes. These must sum to 1 (however, the last element is always assumed to account for the remaining probability, as long as sum(pvals[:-1]) <= 1) .

size : int or tuple of ints, optional

Output shape. If the given shape is, e.g., (m, n, k) , then m * n * k samples are drawn. Default is None, in which case a single value is returned.

Returns

out : ndarray

The 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.

Draw samples from a multinomial distribution.

See Also

Generator.multinomial

which should be used for new code.

Examples

Throw a dice 20 times:

This example is valid syntax, but we were not able to check execution
>>> np.random.multinomial(20, [1/6.]*6, size=1)  # doctest: +SKIP
array([[4, 1, 7, 5, 2, 1]]) # random

It landed 4 times on 1, once on 2, etc.

Now, throw the dice 20 times, and 20 times again:

This example is valid syntax, but we were not able to check execution
>>> np.random.multinomial(20, [1/6.]*6, size=2)  # doctest: +SKIP
array([[3, 4, 3, 3, 4, 3], # random
       [2, 4, 3, 4, 0, 7]])

For the first run, we threw 3 times 1, 4 times 2, etc. For the second, we threw 2 times 1, 4 times 2, etc.

A loaded die is more likely to land on number 6:

This example is valid syntax, but we were not able to check execution
>>> np.random.multinomial(100, [1/7.]*5 + [2/7.])  # doctest: +SKIP
array([11, 16, 14, 17, 16, 26]) # random

The probability inputs should be normalized. As an implementation detail, the value of the last entry is ignored and assumed to take up any leftover probability mass, but this should not be relied on. A biased coin which has twice as much weight on one side as on the other should be sampled like so:

This example is valid syntax, but we were not able to check execution
>>> np.random.multinomial(100, [1.0 / 3, 2.0 / 3])  # RIGHT  # doctest: +SKIP
array([38, 62]) # random

not like:

This example is valid syntax, but we were not able to check execution
>>> np.random.multinomial(100, [1.0, 2.0])  # WRONG  # doctest: +SKIP
Traceback (most recent call last):
ValueError: pvals < 0, pvals > 1 or pvals contains NaNs
See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /dask/array/random.py#323
type: <class 'function'>
Commit: