mindspore.ops.Bernoulli
- 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
- Inputs:
x (Tensor) - Input Tensor. Data type must be int8, uint8, int16, int32, int64, bool, float32 or float64.
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
>>> 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.]