mindspore.ops.multinomial_with_replacement

View Source On Gitee
mindspore.ops.multinomial_with_replacement(x, seed, offset, numsamples, replacement=False)[source]

Generate a tensor from a multinomial distribution.

Note

  • The rows of input do not need to sum to one (in which case we use the values as weights), but must be non-negative, finite and have a non-zero sum.

  • If seed is set to be -1 , and offset is set to be 0, the random number generator is seeded by a random seed.

Parameters
  • x (Tensor) – The 1-D or 2-D input tensor containing probabilities.

  • seed (int) – Random seed.

  • offset (int) – Offset.

  • numsamples (int) – The number of samples to draw.

  • replacement (bool, optional) – Whether to draw with replacement or not. Default False .

Returns

Tensor

Supported Platforms:

CPU

Examples

>>> import mindspore
>>> x = mindspore.tensor([[0., 9., 4., 0.]], mindspore.float32)
>>> mindspore.ops.multinomial_with_replacement(x, 2, 5, 2, True)
Tensor(shape=[1, 2], dtype=Int64, value=
[[1, 1]])