oneflow.bernoulli

oneflow.bernoulli(x, *, generator=None, out=None)

This operator returns a Tensor with binaray random numbers (0 / 1) from a Bernoulli distribution.

Parameters
  • x (Tensor) – the input tensor of probability values for the Bernoulli distribution

  • 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)