jax.random.bernoulli#
- jax.random.bernoulli(key, p=np.float32(0.5), shape=None)[source]#
Sample Bernoulli random values with given shape and mean.
The values are distributed according to the probability mass function:
\[f(k; p) = p^k(1 - p)^{1 - k}\]where \(k \in \{0, 1\}\) and \(0 \le p \le 1\).
- Parameters:
key (ArrayLike) – a PRNG key used as the random key.
p (RealArray) – optional, a float or array of floats for the mean of the random variables. Must be broadcast-compatible with
shape
. Default 0.5.shape (Shape | None | None) – optional, a tuple of nonnegative integers representing the result shape. Must be broadcast-compatible with
p.shape
. The default (None) produces a result shape equal top.shape
.
- Returns:
A random array with boolean dtype and shape given by
shape
ifshape
is not None, or elsep.shape
.- Return type: