class gammapy.utils.distributions.GeneralRandomArray(pdf)[source]

Bases: object

Draw random indices from a discrete probability distribution given by a numpy array. The array dimension can be arbitrary.

Note that drawing a random number from an array with N entries is not a constant cost operation. Even the efficient implementation using a binary tree used here costs log(N).

For a general description of the method see the end of the following page:

Methods Summary

draw([n, return_flat_index, random_state]) Returns n draws from the pdf.

Methods Documentation

draw(n=1, return_flat_index=False, random_state='random-seed')[source]

Returns n draws from the pdf.

If return_flat_index == true, a linearized index is returned.

random_state : {int, ‘random-seed’, ‘global-rng’, RandomState}

Defines random number generator initialisation. Passed to get_random_state.