{ } Raw JSON

bundles / skimage 0.26.1rc0.dev0+git20260530.b607368ff / skimage / util / noise / _bernoulli

function

skimage.util.noise:_bernoulli

source: /dev/scikit-image/src/skimage/util/noise.py :8

Signature

def   _bernoulli ( p shape * rng )

Summary

Bernoulli trials at a given probability of a given size.

Extended Summary

This function is meant as a lower-memory alternative to calls such as np.random.choice([True, False], size=image.shape, p=[p, 1-p]). While np.random.choice can handle many classes, for the 2-class case (Bernoulli trials), this function is much more efficient.

Parameters

p : float

The probability that any given trial returns True.

shape : int or tuple of (int, ...)

The shape of the ndarray to return.

rng : `numpy.random.Generator`

Generator instance, typically obtained via np.random.default_rng().

Returns

out : ndarray[bool]

The results of Bernoulli trials in the given size where success occurs with probability p.

Aliases

  • skimage.util.noise._bernoulli