mindspore.ops.MultinomialWithReplacement
- class mindspore.ops.MultinomialWithReplacement(numsamples, replacement=False)[source]
Returns a tensor where each row contains numsamples indices sampled from the multinomial distribution with replacement. It diffs from Multinomial in that it allows the same outcome to be chosen multiple times.
Warning
This is an experimental API that is subject to change or deletion.
Refer to
mindspore.ops.multinomial_with_replacement()
for more details.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:
x (Tensor) - the input tensor containing the cumsum of probabilities, must be 1 or 2 dimensions.
seed (Tensor) - If seed and 'offset' are both set to 0, the random number generator is seeded by a random seed. Otherwise, it is seeded by the given seed and offset. Supported dtype: int64.
offset (Tensor) - Offset used to avoid seed collision. Supported dtype: int64.
- Outputs:
Tensor with the same rows as x, each row has numsamples sampled indices.
- Supported Platforms:
CPU
Examples
>>> from mindspore import Tensor, ops >>> from mindspore import dtype as mstype >>> x = Tensor([[0., 9., 4., 0.]], mstype.float32) >>> seed = Tensor(2, mstype.int64) >>> offset = Tensor(5, mstype.int64) >>> multinomialwithreplacement = ops.MultinomialWithReplacement(numsamples=2,replacement=True) >>> output = multinomialwithreplacement(x, seed, offset) >>> print(output) [[1 1]]