0
0
NumPydata~10 mins

Random sampling distributions in NumPy - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to generate 1000 random samples from a normal distribution with mean 0 and standard deviation 1.

NumPy
samples = np.random.normal(loc=0, scale=[1], size=1000)
Drag options to blanks, or click blank then click option'
A-1
B0
C10
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 as standard deviation causes no variation in samples.
Using negative values for standard deviation is invalid.
2fill in blank
medium

Complete the code to generate 500 random samples from a uniform distribution between 10 and 20.

NumPy
samples = np.random.uniform(low=[1], high=20, size=500)
Drag options to blanks, or click blank then click option'
A10
B0
C20
D15
Attempts:
3 left
💡 Hint
Common Mistakes
Setting low greater than high causes errors.
Using 0 instead of 10 changes the range.
3fill in blank
hard

Fix the error in the code to generate 100 samples from a binomial distribution with 10 trials and success probability 0.5.

NumPy
samples = np.random.binomial(n=10, p=[1], size=100)
Drag options to blanks, or click blank then click option'
A1.5
B0.5
C-0.5
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using values greater than 1 or negative for p causes errors.
Confusing number of trials n with probability p.
4fill in blank
hard

Fill both blanks to create a dictionary of sample means from 1000 samples each, for sample sizes 10 and 50, using a normal distribution with mean 0 and std 1.

NumPy
means = {size: np.mean(np.random.normal(loc=0, scale=1, size=[1])) for size in [[2], 50]}
Drag options to blanks, or click blank then click option'
A10
B20
C30
D40
Attempts:
3 left
💡 Hint
Common Mistakes
Using a fixed size instead of the variable size.
Mismatching sample sizes between the dictionary keys and sample generation.
5fill in blank
hard

Fill all three blanks to create a dictionary of sample variances from 500 samples each, for sample sizes 20 and 100, using a uniform distribution between 0 and 1.

NumPy
variances = {size: np.var(np.random.uniform(low=0, high=[1], size=[2]), ddof=[3]) for size in [20, 100]}
Drag options to blanks, or click blank then click option'
A1
B500
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using ddof=0 gives population variance, not sample variance.
Using wrong sample size causes incorrect variance calculation.