choice#

pybear.new_numpy.random.choice(a, shape, replace=True, n_jobs=None)#

Randomly select elements from the given pool a, with or without replacement, to fill a numpy array of size shape.

This module improves on the impossible slowness of numpy.random.choice on large a when replace=False. Enter a as a 1-dimensional vector. A ‘p’ argument is not available as this algorithm relies on the assumption of equal likelihood for all values in a.

Parameters:
aSequence[Any]

1-dimensional list-like of elements to randomly choose from.

shapeint | Sequence[int]

Shape of returned numpy array containing the randomly selected values.

replacebool

Select values from a with (True) or without (False) replacement of previous pick.

n_jobsint | None, default=None

Number of CPU cores used when parallelizing over subpartitions of a during selection. -1 means using all processors.

Returns:
pickednumpy.ndarray[Any] of shape ‘shape’

Elements randomly selected from a.

See also

numpy.random.choice

Examples

>>> from pybear.new_numpy.random import choice as pb_choice
>>> result = pb_choice(list(range(20)), (3,2), n_jobs=1)
>>> print(result)
[[ 9  6]
 [ 2  0]
 [11  8]]