class brainpy.math.random.bernoulli(p=0.5, size=None, key=None)[source]#

Sample Bernoulli random values with given shape and mean.

  • p (float, array_like, optional) – A float or array of floats for the mean of the random variables. Must be broadcast-compatible with shape and the values should be within [0, 1]. Default 0.5.

  • size (optional, tuple of int, int) – A tuple of nonnegative integers representing the result shape. Must be broadcast-compatible with p.shape. The default (None) produces a result shape equal to p.shape.


out – A random array with boolean dtype and shape given by shape if shape is not None, or else p.shape.

Return type: