mindspore.ops.random_categorical
- mindspore.ops.random_categorical(logits, num_sample, seed=0, dtype=mstype.int64)[source]
Generates random samples from a given categorical distribution tensor.
Warning
The Ascend backend does not support the reproducibility of random numbers, so the seed parameter has no effect.
This interface is deprecated and will be removed after version 2.9.0.
- Parameters
logits (Tensor) – The input tensor. 2-D Tensor with shape \((batch\_size, num\_classes)\).
num_sample (int) – Number of sample to be drawn. Only constant values are allowed.
seed (int) – Random seed. Only constant values are allowed. Default:
0.dtype (mindspore.dtype) – The type of output. Its value must be one of mindspore.int16, mindspore.int32 and mindspore.int64. Default:
mstype.int64.
- Returns
Tensor. The output Tensor with shape \((batch\_size, num\_samples)\).
- Raises
- Supported Platforms:
AscendGPUCPU
Examples
>>> from mindspore import ops >>> from mindspore import Tensor >>> import mindspore.common.dtype as mstype >>> import numpy as np >>> logits = Tensor(np.random.random((10, 5)).astype(np.float32), mstype.float32) >>> net = ops.random_categorical(logits, 8) >>> result = net.shape >>> print(result) (10, 8)