bernoulli
- paddle. bernoulli ( x: Tensor, p: float | None = None, name: str | None = None ) Tensor [source]
- 
         For each element \(x_i\) in input x, take a sample from the Bernoulli distribution, also called two-point distribution, with success probability \(x_i\). The Bernoulli distribution with success probability \(x_i\) is a discrete probability distribution with probability mass function\[\begin{split}p(y)=\begin{cases} x_i,&y=1\\ 1-x_i,&y=0 \end{cases}.\end{split}\]- Parameters
- 
           - x (Tensor) – The input Tensor, it’s data type should be float32, float64. 
- p (float|None, optional) – If - pis given, the success probability will always be- p. Default is None, which means to use the success probability specified by input- x.
- name (str|None, optional) – For details, please refer to api_guide_Name. Generally, no setting is required. Default: None. 
 
- Returns
- 
           Tensor, A Tensor filled samples from Bernoulli distribution, whose shape and dtype are same as x.
 Examples >>> import paddle >>> paddle.set_device('cpu') # on CPU device >>> paddle.seed(100) >>> x = paddle.rand([2,3]) >>> print(x) >>> Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True, [[0.55355281, 0.20714243, 0.01162981], [0.51577556, 0.36369765, 0.26091650]]) >>> >>> out = paddle.bernoulli(x) >>> print(out) >>> Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True, [[1., 0., 1.], [0., 1., 0.]]) >>> >>> out = paddle.bernoulli(x, p=0) >>> print(out) Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True, [[0., 0., 0.], [0., 0., 0.]]) 
