Samples from a rolled die
Let's work through generating a simulation using the numpy package. You'll work with the same scenario from the slides, simulating rolls from a standard die numbered 1 through 6, using the randint() function. Take a look at the documentation for this function if you haven't encountered it before.
Starting with a small sample and working your way up to a larger sample, examine the outcome means and come to a conclusion about the underlying theorem.
Cet exercice fait partie du cours
Practicing Statistics Interview Questions in Python
Instructions
- Generate a sample of 10 die rolls using the
randint()function; assign it to oursmallvariable. - Assign the mean of the sample to
small_meanand print the results; notice how close it is to the true mean. - Similarly, create a larger sample of 1000 die rolls and assign the list to our
largevariable. - Assign the mean of the larger sample to
large_meanand print the mean; which theorem is at work here?
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
from numpy.random import randint
# Create a sample of 10 die rolls
small = randint(____, ____, ____)
# Calculate and print the mean of the sample
small_mean = ____
print(____)
# Create a sample of 1000 die rolls
large = randint(____, ____, ____)
# Calculate and print the mean of the large sample
large_mean = ____
print(____)