mindspore.Tensor.random_categorical
- Tensor.random_categorical(num_sample, seed=0, dtype=mstype.int64)[source]
Generates random samples from a given categorical distribution tensor.
- Parameters
num_sample (int) – Number of sample to be drawn. Only constant values is allowed.
seed (int) – Random seed.Only constant values is allowed. Default: 0
dtype (mindspore.dtype) – The type of output. Its value must be one of mindspore.int16, mindspore.int32 and mindspore.int64. Default: mindspore.int64.
- Returns
Tensor, the output Tensor with shape \((batch\_size, num\_samples)\).
- Raises
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import numpy as np >>> import mindspore.common.dtype as mstype >>> from mindspore import Tensor >>> x = Tensor(np.random.random((10, 5)).astype(np.float32), mstype.float32) >>> output = x.random_categorical(8) >>> result = output.shape >>> print(result) (10, 8)