CommencerCommencer gratuitement

Sampling from a discrete uniform distribution

Tom has a regular six-sided die showing the numbers one through six. In this exercise, you'll use the discrete uniform distribution, which is perfectly suited for sampling integer values with uniform distributions, to simulate rolling Tom's die 1,000 times. You'll then visualize the results!

The following have been imported for you: seaborn as sns, scipy.stats as st and matplotlib.pyplot as plt.

Cet exercice fait partie du cours

Monte Carlo Simulations in Python

Afficher le cours

Instructions

  • Define low and high for use in .rvs() sampling in the next step; your distribution should include integer values from one (the lowest possible roll outcome) through six (the highest possible roll outcome) uniformly.
  • Sample 1,000 times from the discrete uniform distribution represented by st.randint with integer values one through six.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Define low and high for use in rvs sampling below
low = ____
high = ____
# Sample 1,000 times from the discrete uniform distribution
samples = ____

samples_dict = {'nums':samples}
sns.histplot(x='nums', data=samples_dict, bins=6, binwidth=0.3)
plt.show()
Modifier et exécuter le code