mlx.core.random.bernoulli#

bernoulli(p: scalar | array = 0.5, shape: Sequence[int] | None = None, key: array | None = None, stream: None | Stream | Device = None) array#

Generate Bernoulli random values.

The values are sampled from the bernoulli distribution with parameter p. The parameter p can be a float or array and must be broadcastable to shape.

Parameters:
  • p (float or array, optional) – Parameter of the Bernoulli distribution. Default is 0.5.

  • shape (list(int), optional) – Shape of the output. The default shape is p.shape.

  • key (array, optional) – A PRNG key. Default: None.

Returns:

The array of random integers.

Return type:

array