Skip to content
← All questions

How are the two report completion-time arrays generated in NumPy?

The two report completion-time arrays are generated using the `np.random.uniform` function. Report A is modeled by drawing `sims` independent values from a uniform distribution on the interval from 1 to 5 hours, and Report B is modeled by drawing `sims` independent values from a uniform distribution on the interval from 2 to 6 hours.

Conditions

  • Use the uniform model introduced earlier.
  • `sims` must already be defined.

Reasoning, step by step

  1. Set the number of simulation runs to one million with `sims = 1000000`.
  2. Generate one million random completion times for report A from the interval 1 to 5 hours using `A = np.random.uniform(1, 5, sims)`.
  3. Generate one million random completion times for report B from the interval 2 to 6 hours using `B = np.random.uniform(2, 6, sims)`.
  4. Compute the total completion time for each paired simulation run by adding A and B using `duration = A+BA + B`.

Example

The code lines visible are `A = np.random.uniform(1, 5, sims)` and `B = np.random.uniform(2, 6, sims)`. The narrator states, "they will take anywhere between 1 to 5 hours and 2 to 6 hours to complete, so let's define those values for the arguments for these functions."

Common misconceptions

  • Assuming the arrays are generated with a normal distribution instead of a uniform distribution.
  • Forgetting that the third argument in `np.random.uniform` specifies the number of samples to generate.

Watch the explanation

Explore next

Answers are generated from source material and independently checked. Consult the original video or creator if something is unclear.