mlx.core.random.bernoulli#

mlx.core.random.bernoulli(p: Union[bool, int, float, complex, object] = 0.5, shape: Optional[List[int]] = None, key: Optional[array] = None, stream: Union[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