mindspore.ops.Bernoulli

View Source On Gitee
class mindspore.ops.Bernoulli(seed=- 1, offset=0)[source]

Randomly set the elements of output to 0 or 1 with the probability of P which follows the Bernoulli distribution.

Warning

This is an experimental API that is subject to change or deletion.

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

Parameters
  • seed (int, optional) – The seed value for random generating. The value of seed must be -1 or a positive integer, and -1 means using the current timestamp. Default: -1 .

  • offset (int, optional) – Used to change the starting position during the generation of random number sequence. Default: 0 .

Inputs:
  • x (Tensor) - Input Tensor.

  • p (Union[Tensor, float], optional) - Success probability, representing the probability of setting 1 for the corresponding position of the current Tensor. It has the same shape as x, the value of p must be in the range [0, 1]. Default: 0.5 .

Outputs:
  • y (Tensor) - with the same shape and type as x .

Supported Platforms:

GPU CPU

Examples

>>> import mindspore
>>> from mindspore import Tensor, ops
>>> input_x = Tensor([0.1, 0.2, 0.3], mindspore.float32)
>>> bernoulli = ops.Bernoulli()
>>> output = bernoulli(input_x, Tensor([1.0]))
>>> print(output)
[1. 1. 1.]
>>> input_p = Tensor([0.0, 1.0, 1.0], mindspore.float32)
>>> output = bernoulli(input_x, input_p)
>>> print(output)
[0. 1. 1.]