sample_bernoulli#

sionna.phy.utils.sample_bernoulli(shape: List[int] | Tuple[int, ...] | torch.Size, p: float | torch.Tensor, precision: Literal['single', 'double'] | None = None, device: str | None = None) torch.Tensor[source]#

Generates samples from a Bernoulli distribution with probability p.

Parameters:
  • shape (List[int] | Tuple[int, ...] | torch.Size) – Shape of the tensor to sample.

  • p (float | torch.Tensor) – Probability (broadcastable with shape).

  • precision (Literal['single', 'double'] | None) – Precision used for internal calculations. If set to None, precision is used.

  • device (str | None) – Device for computation. If None, device is used.

Outputs:

samples – Binary samples (boolean tensor).

Examples

from sionna.phy.utils import sample_bernoulli

samples = sample_bernoulli([100], p=0.3)
print(samples.sum().item())  # Approximately 30