NumPy.arange returns evenly spaced values over a specified interval. Its stop value is excluded, so it constructs integer populations for random sampling and discrete probability calculations. section 12.3.2 section 3.1.2
Use the stop argument to control whether the final intended value appears:
- np.arange(1, 10) produces integers from 1 through 9, making a nine-value population for random selection. section 12.3.2
- np.arange(0, n + 1) produces possible success counts from 0 through n; n + 1 is required because the stop value is excluded. section 3.1.2
Build a sampling population
>>> df3 = df3.assign(random_distribution =\n>>> np.random.choice(np.arange(1, 10), size = 1000))\n\nThe range supplies candidate values, while random choice samples 1,000 values with replacement. Grouping and counting the results supports comparison of the observed distribution. section 12.3.2
>>> n = 20 >>> k = np.arange(0, n + 1) >>> p = [0.20, 0.50]
Inspect the range used to enumerate every possible number of successes in 20 trials. section 3.1.2
