poisson_noise

sherpa.utils.poisson_noise(x: SupportsFloat, rng: Generator | RandomState | None = None) float64[source] [edit on github]
sherpa.utils.poisson_noise(x: Sequence[SupportsFloat], rng: Generator | RandomState | None = None) ndarray

Draw samples from a Poisson distribution.

Parameters:
xscalar or array

The expectation value for the distribution.

rngnumpy.random.Generator, numpy.random.RandomState, or None, optional

Determines how the random numbers are created. If set to None then the numpy.random.poisson routine is used.

Returns:
outscalar or array

A random realisation of the input array, drawn from the Poisson distribution, as a SherpaFloat.

Notes

All input values less than zero are replaced by zero.

Examples

When the rng parameter is left as None then the legacy Numpy random API is used:

>>> np.random.seed(17389)
>>> poisson_noise([10, 20, 5])
array([ 7.,  20.,   6.])

Note that the seed used by the legacy Numpy is not guaranteed to match the behavior of the numpy generators:

>>> rng = np.random.default_rng(17389)
>>> poisson_noise([10, 20, 5], rng=rng)
array([12., 31., 7.])