# mxnet.ndarray.random.multinomial¶

mxnet.ndarray.random.multinomial(data, shape=_Null, get_prob=False, out=None, dtype='int32', **kwargs)[source]

Concurrent sampling from multiple multinomial distributions.

Note

The input distribution must be normalized, i.e. data must sum to 1 along its last dimension.

Parameters
• data (NDArray) – An n dimensional array whose last dimension has length k, where k is the number of possible outcomes of each multinomial distribution. For example, data with shape (m, n, k) specifies m*n multinomial distributions each with k possible outcomes.

• shape (int or tuple of ints, optional) – The number of samples to draw from each distribution. If shape is empty one sample will be drawn from each distribution.

• get_prob (bool, optional) – If true, a second array containing log likelihood of the drawn samples will also be returned. This is usually used for reinforcement learning, where you can provide reward as head gradient w.r.t. this array to estimate gradient.

• out (NDArray, optional) – Store output to an existing NDArray.

• dtype (str or numpy.dtype, optional) – Data type of the sample output array. The default is int32. Note that the data type of the log likelihood array is the same with that of data.

Examples

>>> probs = mx.nd.array([[0, 0.1, 0.2, 0.3, 0.4], [0.4, 0.3, 0.2, 0.1, 0]])
>>> mx.nd.random.multinomial(probs)
[3 1]
<NDArray 2 @cpu(0)>
>>> mx.nd.random.multinomial(probs, shape=2)
[[4 4]
[1 2]]
<NDArray 2x2 @cpu(0)>
>>> mx.nd.random.multinomial(probs, get_prob=True)
[3 2]
<NDArray 2 @cpu(0)>
[-1.20397282 -1.60943794]
<NDArray 2 @cpu(0)>