mindspore.ops.choice_with_mask

mindspore.ops.choice_with_mask(input_x, count=256, seed=0, seed2=0)[source]

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

The input_x must be a tensor whose rank is not less than 1. If its rank is greater than or equal to 2, the first dimension specifies the number of samples. The returned index tensor denotes the index of the nonzero sample, the mask tensor denotes which elements in the index tensor are valid.

Parameters
  • 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.

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

  • seed (int) – Random seed. Default: 0.

  • seed2 (int) – Random seed2. Default: 0.

Returns

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.

Raises
Supported Platforms:

Ascend GPU CPU

Examples

>>> input_x = Tensor(np.ones(shape=[240000, 4]).astype(np.bool))
>>> output_y, output_mask = ops.choice_with_mask(input_x)
>>> result = output_y.shape
>>> print(result)
(256, 2)
>>> result = output_mask.shape
>>> print(result)
(256,)