- paddle. bernoulli ( x, name=None )
This OP returns a Tensor filled with random binary(0 or 1) number from a Bernoulli distribution. The input
xis a tensor with probabilities for generating the random binary number. Each element in
xshould be in [0, 1], and the out is generated by:\[out_i ~ Bernoulli (x_i)\]
x (Tensor) – A tensor with probabilities for generating the random binary number. The data type should be float32, float64.
name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name.
A Tensor filled with random binary number with the same shape and dtype as
- Return type
import paddle paddle.set_device('cpu') # on CPU device paddle.seed(100) x = paddle.rand([2,3]) print(x) # [[0.55355281, 0.20714243, 0.01162981], # [0.51577556, 0.36369765, 0.26091650]] out = paddle.bernoulli(x) print(out) # [[1., 0., 1.], # [0., 1., 0.]]