mindspore.ops.RandomChoiceWithMask

class mindspore.ops.RandomChoiceWithMask(count=256, seed=0, seed2=0)[source]

Generates a random sample as index tensor with a mask tensor from a given tensor.

Refer to mindspore.ops.choice_with_mask() for more details.

Note

  • Random seed: a set of regular random numbers can be obtained through some complex mathematical algorithms, and the random seed is the initial value of this random number. If the random seed is the same in two separate calls, the random number generated will not change.

  • Global random seed and operator-level random seed are not set or both set to 0: behavior is completely random.

  • Global random seed is set, but operator-level random seed is not set: A global random seed will splice with 0 to generate random number.

  • Global random seed is not set, operator-level random seed is set: 0 splices with the operator-level random seed to generate random number.

  • Both Global random and operator-level random seed are set: the global random seed will splice with the operator-level random seed to generate random number.

Parameters
  • count (int, optional) – Number of items expected to get and the number must be greater than 0. Default: 256 .

  • seed (int, optional) – The operator-level random seed, used to generate random numbers, must be non-negative. Default: 0 .

  • seed2 (int, optional) – The global random seed, which combines with the operator-level random seed to determine the final generated random number, must be non-negative. Default: 0 .

Inputs:
  • input_x (Tensor[bool]) - The input tensor. The input tensor rank must be greater than or equal to 1 and less than or equal to 5.

Outputs:

Two tensors, the first one is the index tensor and the other one is the mask tensor.

  • index (Tensor) - The output shape is 2-D.

  • mask (Tensor) - The output shape is 1-D.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> rnd_choice_mask = ops.RandomChoiceWithMask()
>>> input_x = Tensor(np.ones(shape=[240000, 4]).astype(np.bool))
>>> output_y, output_mask = rnd_choice_mask(input_x)
>>> result = output_y.shape
>>> print(result)
(256, 2)
>>> result = output_mask.shape
>>> print(result)
(256,)