#15922·numpy

Add `select()` to allow `choice(..., replace=False)` with `size=`

Author: elmanmCreated Apr 7, 2020Updated Sep 30, 2026
Labels01 - Enhancement15 - Discussioncomponent: numpy.random62 - Python API

To be able to vectorise random sampling with/without replacement is would be useful to be able to set the replace flag in random.choice to a tuple matching the shape of size. i.e.

# THIS IS NOT A WORKING CODE
from numpy import np

x = [i for i in range(100)]
k = np.random.poission(0.5, 10)
samples = np.random.choice(x, size=(10, 10), replace=(False, True), p=k)

This would allow for a much neater way to produce a 2D array where each row is a sample from the same population taken without replacement.

EDIT(seberg): The above may be a bit confusing, I suggest going down to https://github.com/numpy/numpy/issues/15922#issuecomment-782164807 which, to me, is the sensible proposal.