Replacement is a sampling condition in which a selected item returns before the next selection. It permits repeated selections and commonly supports independent random samples; without replacement, each selection changes the remaining population and subsequent probabilities. section 12.3.2 section 3.2.3
Use the condition to choose the appropriate probability model:
- With replacement, select the same value or item more than once; NumPy uses replace = True for this behavior. section 12.3.2 section 9.3.4
- Without replacement, remove each selected item, so later probabilities use a changed numerator and denominator. section 3.2.3
- For counting, distinguish combinations and permutations by whether order matters, then account for whether repeated selection is allowed. section 3.2
Cards versus repeated random draws
Drawing two face cards without replacement gives (12/52) × (11/51), approximately 5%, because the first card is removed. By contrast, sampling 1,000 values from 1 through 9 with replacement allows values to recur, producing varying group counts. section 3.2.3 section 12.3.2
>>> df3 = df3.assign(random_distribution = >>> np.random.choice(np.arange(1, 10), size = 1000))
Inspect NumPy code that samples 1,000 integers with replacement and stores the result in a data frame. section 12.3.2
>>> random_digits = np.random.choice(100, 500, replace = True)
Inspect a larger NumPy sample using replace = True for repeated random selections in a simulation. section 9.3.4
