Your first simulationLesson 02 of 76 · 6 min
What counts as one trial?
Identify the simulated unit and retain all outcomes belonging to it.
A trial contains one complete outcome for the question. A NumPy array stores values in a numbered arrangement and applies arithmetic to its entries. A two-dimensional array is a matrix: rows and columns. Here one row is one event and one column is one guest. Individual guests are ingredients, not separate observations of overflow.
Inspect the invented two-event example first: [[1,0,1],[0,1,0]]. Its shape (2,3) means two rows and three columns. Summing with axis=1 works across each row, giving attendance [2,1]. With axis=0 it works down the rows, giving guest-column totals [1,1,1]. Each 1 means attends; each 0 means absent. The code prints both calculations before generating more events.
A uniform random draw on [0,1) gives equally likely intervals of equal width: a draw below 0.6 occurs with chance 0.6. Comparing draws with that threshold gives boolean attendance decisions. Summarise each row before testing overflow. Averaging every cell instead estimates a guest attendance fraction. Later, x[:,0] selects every row of column 0; x[:3] selects the first three rows. Python starts numbering at zero.
Does averaging individual guest decisions estimate the probability of an event overflowing?
Write a prediction (optional)
Seeded teaching simulation
Select Run Python below with the code unchanged.
A saved draft is open. To run the published example, open Tools and select Restore example. Recover draft brings your code back.
Execution error
Technical error details
Your result
Published example output
This result comes from the original Python. Your runs appear above. Build environment ↗
INVENTED two-event shape: (2, 3) Across each row (axis=1): [2 1] Down each column (axis=0): [1 1 1] Rows=events, columns=guests: [[1 1 1 0 1 1 0 0] [1 1 0 1 1 1 1 1] [1 0 0 1 1 0 0 1] [1 0 1 1 1 0 1 1] [0 1 1 1 0 0 0 1] [1 1 0 0 0 1 0 0]] Attendance per event: [5 7 4 6 4 3] Fraction of events above 5 guests: 0.3333333333333333 Guest attendance fraction: 0.6041666666666666
Read the first result
The first three lines show sums of the invented matrix. Attendance per event sums each simulated row. Compare the event overflow fraction with Guest attendance fraction. They count different things.
Try an edit
Replace rng.random((6, 8)) with rng.random((10000, 8)). Select Run Python again. Compare Rows=events, columns=guests, Fraction of events above 5 guests and Guest attendance fraction. NumPy abbreviates the larger printed matrix. Each simulated row still holds eight guest decisions. Which fraction answers the event question?
Scope. The rows and guest draws are independent in this model. Real events can share common influences.
Try a fresh case
For a five-task project, which object should one deadline trial contain?
Need a hint?
Hint 1
Name the outcome the decision concerns.
Hint 2
List the inputs needed to calculate one such outcome.