oneflow.bernoulli¶
-
oneflow.
bernoulli
(input, p, *, generator=None, out=None)¶ This operator returns a Tensor with binaray random numbers (0 / 1) from a Bernoulli distribution.
- Parameters
input (Tensor) – the input tensor of probability values for the Bernoulli distribution
p (float, optional) – the probability for the Bernoulli distribution. If specified, Bernoulli distribution will use p for sampling, not input
generator (Generator, optional) – a pseudorandom number generator for sampling
out (Tensor, optional) – the output tensor.
- Shape:
Input: \((*)\). Input can be of any shape
Output: \((*)\). Output is of the same shape as input
For example:
>>> import numpy as np >>> import oneflow as flow >>> arr = np.array( ... [ ... [1.0, 1.0, 1.0], ... [1.0, 1.0, 1.0], ... [1.0, 1.0, 1.0], ... ] ... ) >>> x = flow.tensor(arr, dtype=flow.float32) >>> y = flow.bernoulli(x) >>> y tensor([[1., 1., 1.], [1., 1., 1.], [1., 1., 1.]], dtype=oneflow.float32) >>> y = flow.bernoulli(x, 1) >>> y tensor([[1., 1., 1.], [1., 1., 1.], [1., 1., 1.]], dtype=oneflow.float32) >>> y = flow.bernoulli(x, p=0) >>> y tensor([[0., 0., 0.], [0., 0., 0.], [0., 0., 0.]], dtype=oneflow.float32)