0
0
NumPydata~20 mins

Random sampling distributions in NumPy - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Random Sampling Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1:30remaining
Output of sampling from a normal distribution
What is the shape of the array produced by this code?
NumPy
import numpy as np
sample = np.random.normal(loc=0, scale=1, size=(5, 3))
print(sample.shape)
A(5, 3)
B(3, 5)
C(5,)
D(15,)
Attempts:
2 left
💡 Hint
The size parameter defines the shape of the output array.
data_output
intermediate
1:30remaining
Mean of samples from uniform distribution
What is the approximate mean of the samples generated by this code?
NumPy
import numpy as np
samples = np.random.uniform(low=10, high=20, size=10000)
print(round(samples.mean(), 1))
A15.0
B10.0
C20.0
D5.0
Attempts:
2 left
💡 Hint
The mean of a uniform distribution is the midpoint between low and high.
visualization
advanced
2:00remaining
Histogram shape of binomial samples
Which histogram shape best describes the samples from this binomial distribution?
NumPy
import numpy as np
import matplotlib.pyplot as plt
samples = np.random.binomial(n=10, p=0.5, size=1000)
plt.hist(samples, bins=range(12), edgecolor='black')
plt.show()
ASingle spike at 10
BSymmetric bell-shaped around 5
CSkewed heavily to the right
DUniform flat distribution
Attempts:
2 left
💡 Hint
Binomial with p=0.5 tends to be symmetric around n*p.
🧠 Conceptual
advanced
1:30remaining
Effect of sample size on sample mean variance
If you increase the sample size from 10 to 1000 when sampling from a normal distribution, what happens to the variance of the sample mean?
AIt stays the same because variance depends only on the distribution
BIt increases because more data adds more variability
CIt decreases because larger samples give more stable means
DIt becomes zero because large samples have no variance
Attempts:
2 left
💡 Hint
Think about how averaging many values affects variability.
🔧 Debug
expert
1:30remaining
Identify the error in random sampling code
What error does this code raise when run?
NumPy
import numpy as np
samples = np.random.normal(loc=0, scale=1, size=-5)
print(samples)
ANo error, prints an empty array
BTypeError: size must be an integer or tuple of integers
CSyntaxError: invalid syntax
DValueError: negative dimensions are not allowed
Attempts:
2 left
💡 Hint
Check the size parameter for validity.