0
0
SciPydata~10 mins

Random variable generation in SciPy - 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 5 random numbers from a normal distribution with mean 0 and standard deviation 1.

SciPy
from scipy.stats import norm
samples = norm.[1](loc=0, scale=1, size=5)
print(samples)
Drag options to blanks, or click blank then click option'
Apdf
Bcdf
Crvs
Dppf
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'pdf' or 'cdf' instead of 'rvs' which do not generate samples.
Confusing 'ppf' with sample generation.
2fill in blank
medium

Complete the code to generate 10 random values from a uniform distribution between 0 and 1.

SciPy
from scipy.stats import uniform
samples = uniform.[1](loc=0, scale=1, size=10)
print(samples)
Drag options to blanks, or click blank then click option'
Arvs
Bcdf
Cpdf
Dsf
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'cdf' or 'pdf' which calculate probabilities, not samples.
Using 'sf' which is survival function, not sample generation.
3fill in blank
hard

Fix the error in the code to generate 7 random values from an exponential distribution with rate 2 (lambda=2).

SciPy
from scipy.stats import expon
samples = expon.[1](scale=0.5, size=7)
print(samples)
Drag options to blanks, or click blank then click option'
Arvs
Bcdf
Cpdf
Dppf
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'cdf' or 'pdf' which do not generate samples.
Using 'ppf' which calculates quantiles, not samples.
4fill in blank
hard

Fill both blanks to create a dictionary of word lengths for words longer than 4 characters.

SciPy
words = ['apple', 'bat', 'carrot', 'dog', 'elephant']
lengths = {word: [1] for word in words if len(word) [2] 4}
print(lengths)
Drag options to blanks, or click blank then click option'
Alen(word)
Bword
C>
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as the value instead of its length.
Using '<=' instead of '>' in the condition.
5fill in blank
hard

Fill all three blanks to create a dictionary of uppercase words and their lengths for words shorter than 6 characters.

SciPy
words = ['apple', 'bat', 'carrot', 'dog', 'elephant']
result = { [1]: [2] for word in words if len(word) [3] 6 }
print(result)
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
C<
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the original word as key instead of uppercase.
Using '>' instead of '<' in the condition.
Using the word as value instead of its length.