tiled_choice#

pybrops.core.random.sampling.tiled_choice(a, size=None, replace=True, p=None, rng=None)[source]#

Generate a random sample from a given 1-D array.

If sampling without replacement, tile the sampling by filling with complete sets until a complete set cannot be put into the output, then sample without replacement to fill the remaining samples in the output.

Parameters:
  • a (numpy.ndarray, Integral) – If an ndarray, a random sample is generated from its elements. If an Integral, the random sample is generated as if it were np.arange(a)

  • size (Integral, Tuple of Integral, None) – Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. Default is None, in which case a single value is returned.

  • replace (bool) – Whether the sample is with or without replacement. Default is True, meaning that a value of a can be selected multiple times.

  • p (numpy.ndarray, None) – The probabilities associated with each entry in a. If not given, the sample assumes a uniform distribution over all entries in a.

  • rng (numpy.random.Generator, numpy.random.RandomState, None) – A random number generator source. If None, then use the default global random number generator.

Returns:

out – The generated random samples

Return type:

numpy.ndarray