LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Monte Carlo Simulations in Python

Kurs anzeigen

Anleitung zur Übung

  • 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.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# 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()
Code bearbeiten und ausführen