MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Monte Carlo Simulations in Python

Lihat Kursus

Petunjuk latihan

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

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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()
Edit dan Jalankan Kode