mindspore.ops.multinomial
- mindspore.ops.multinomial(inputs, num_sample, replacement=True, seed=None)[source]
Returns a tensor sampled from the multinomial probability distribution located in the corresponding row of the input tensor.
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
inputs (Tensor) – The input tensor containing probabilities, must be 1 or 2 dimensions, with float32 data type.
num_sample (int) – Number of samples to draw.
replacement (bool, optional) – Whether to draw with replacement or not, default True.
seed (int, optional) – Seed is used as entropy source for the random number engines to generate pseudo-random numbers, must be non-negative. Default: 0.
- Outputs:
Tensor, has the same rows with input. The number of sampled indices of each row is num_samples. The dtype is float32.
- Raises
- Supported Platforms:
GPU
Examples
>>> from mindspore import Tensor >>> import mindspore.ops.composite as C >>> from mindspore.common import dtype as mstype >>> input = Tensor([0, 9, 4, 0], mstype.float32) >>> output = C.multinomial(input, 2, True) >>> print(output) [1 1]