mindspore.ops.Multinomial

class mindspore.ops.Multinomial(*args, **kwargs)[source]

Returns a tensor sampled from the multinomial probability distribution located in the corresponding row of tensor input.

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.

Parameters
  • seed (int) – Random seed, must be non-negative. Default: 0.

  • seed2 (int) – Random seed2, must be non-negative. Default: 0.

Inputs:
  • input (Tensor[float32]) - the input tensor containing the cumsum of probabilities, must be 1 or 2 dimensions.

  • num_samples (int32) - number of samples to draw.

Outputs:

Tensor with the same rows as input, each row has num_samples sampled indices.

Raises
  • TypeError – If neither seed nor seed2 is an int.

  • TypeError – If input is not a Tensor whose dtype is float32.

  • TypeError – If dtype of num_samples is not int32.

Supported Platforms:

GPU

Examples

>>> input = Tensor([0., 9., 4., 0.], mstype.float32)
>>> multinomial = ops.Multinomial(seed=10)
>>> output = multinomial(input, 2)
>>> print(output)
[2 1]