liveBook · Manning

Numpy.arange

As explained in Statistics Every Programmer Needs

NumPy.arange is a function that returns evenly spaced values within a specified half-open interval.

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

How Statistics Every Programmer Needs covers it

How deep it goes
Defines half-open range construction and demonstrates integer steps, but does not develop broader array-generation behavior.
Examples
Uses ranges from 1 through 9 for sampling and from 0 through 20 for binomial success counts.
What you can do after
Apply it via NumPy to create integer populations for sampling or discrete probability calculations.
How it connects
Connects to NumPy, random sampling, binomial distribution, probability mass functions, SciPy, and Matplotlib.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Every Programmer Needs. The section links point to the parts of the book it draws on.