mindspore.ops.Multinomial

class mindspore.ops.Multinomial(seed=0, seed2=0, dtype=mstype.int32)[源代码]

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.

  • dtype (dtype) – The type of output, must be int32 or int64. Default: int32.

Inputs:
  • x (Tensor) - the input tensor containing the cumsum of probabilities, must be 1 or 2 dimensions. Must be one of the following types: float16, float32, float64. CPU and GPU supports x 1 or 2 dimensions and Ascend only supports 2 dimensions.

  • num_samples (int) - number of samples to draw, must be a nonnegative number.

Outputs:

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

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

  • TypeError – If x is not a Tensor whose dtype is float16, float32, float64.

  • TypeError – If dtype of num_samples is not int.

  • TypeError – If dtype is not int32 or int64.

Supported Platforms:

Ascend GPU CPU

Examples

>>> x = Tensor([[0., 9., 4., 0.]], mstype.float32)
>>> multinomial = ops.Multinomial(seed=10)
>>> output = multinomial(x, 2)
>>> print(output) # run in CPU
[[1 1]]