Rate this Page

torch.Tensor.bernoulli_#

Tensor.bernoulli_(p=0.5,*,generator=None)Tensor#

Fills each location ofself with an independent sample fromBernoulli(p)\text{Bernoulli}(\texttt{p}).self can have integraldtype.

p should either be a scalar or tensor containing probabilities to beused for drawing the binary random number.

If it is a tensor, theith\text{i}^{th} element ofself tensorwill be set to a value sampled fromBernoulli(p_tensor[i])\text{Bernoulli}(\texttt{p\_tensor[i]}). In this casep must havefloating pointdtype.

See alsobernoulli() andtorch.bernoulli()