用法:
mxnet.ndarray.random.multinomial(data, shape=_Null, get_prob=False, out=None, dtype='int32', **kwargs)
- data:(
NDArray
) - 一个n
最后一个维度有长度的维度数组k
,其中k
是每个多项分布的可能结果的数量。例如,具有形状的数据(m, n, k)
指定m*n
多项分布,每个分布k
可能的结果。 - shape:(
int
or
tuple of ints
,
optional
) - 从每个分布中抽取的样本数。如果 shape 为空,将从每个分布中抽取一个样本。 - get_prob:(
bool
,
optional
) - 如果为真,则还将返回包含抽取样本的对数似然的第二个数组。这通常用于强化学习,您可以在其中提供奖励作为头部梯度 w.r.t。这个数组来估计梯度。 - out:(
NDArray
,
optional
) - 将输出存储到现有的 NDArray。 - dtype:(
str
or
numpy.dtype
,
optional
) - 样本输出数组的数据类型。默认值为 int32。注意对数似然数组的数据类型与data
.
- data:(
对于具有
n
尺寸和形状(d1, d2, …, dn-1, k)
的输入data
以及具有形状(s1, s2, …, sx)
的输入shape
,返回具有形状(d1, d2, … dn-1, s1, s2, …, sx)
的 NDArray。返回的 NDArray 的s1, s2, … sx
维度由从data
的k
维度中提供的每个相应多项分布采样的 0 索引值组成。对于案件
n`=1, and `x`=1 (one shape dimension), returned NDArray has shape `(s1,)
.如果
get_prob
设置为 True,则此函数返回格式列表:[ndarray_output, log_likelihood_output]
,其中log_likelihood_output
是与采样输出具有相同形状的 NDArray。列表,或NDArray
参数:
返回:
返回类型:
来自多个多项分布的并发采样。
注意:
输入分布必须标准化,即
data
必须沿其最后一个维度求和为 1。例子:
>>> probs = mx.nd.array([0, 0.1, 0.2, 0.3, 0.4]) >>> mx.nd.random.multinomial(probs) [3] <NDArray 1 @cpu(0)> >>> 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)>
相关用法
- Python mxnet.ndarray.random.generalized_negative_binomial用法及代码示例
- Python mxnet.ndarray.random.normal用法及代码示例
- Python mxnet.ndarray.random.shuffle用法及代码示例
- Python mxnet.ndarray.random.uniform用法及代码示例
- Python mxnet.ndarray.random.randint用法及代码示例
- Python mxnet.ndarray.random.randn用法及代码示例
- Python mxnet.ndarray.random.negative_binomial用法及代码示例
- Python mxnet.ndarray.random.gamma用法及代码示例
- Python mxnet.ndarray.random.exponential用法及代码示例
- Python mxnet.ndarray.random.poisson用法及代码示例
- Python mxnet.ndarray.random_pdf_generalized_negative_binomial用法及代码示例
- Python mxnet.ndarray.random_pdf_negative_binomial用法及代码示例
- Python mxnet.ndarray.random_pdf_gamma用法及代码示例
- Python mxnet.ndarray.random_pdf_normal用法及代码示例
- Python mxnet.ndarray.random_pdf_poisson用法及代码示例
- Python mxnet.ndarray.random_pdf_dirichlet用法及代码示例
- Python mxnet.ndarray.random_pdf_exponential用法及代码示例
- Python mxnet.ndarray.random_pdf_uniform用法及代码示例
- Python mxnet.ndarray.ravel_multi_index用法及代码示例
- Python mxnet.ndarray.round用法及代码示例
注:本文由纯净天空筛选整理自apache.org大神的英文原创作品 mxnet.ndarray.random.multinomial。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。