0
0
SciPydata~10 mins

Normal distribution 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 import the normal distribution function from scipy.stats.

SciPy
from scipy.stats import [1]

# Now you can use norm to work with normal distribution
Drag options to blanks, or click blank then click option'
Agauss
Bnormal
Cnorm
Dstats
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'normal' instead of 'norm' which is not a valid import.
Trying to import 'gauss' which is not part of scipy.stats.
Importing 'stats' which is the module, not the distribution function.
2fill in blank
medium

Complete the code to calculate the probability density function (PDF) of a normal distribution at x=0.

SciPy
from scipy.stats import norm

pdf_value = norm.pdf([1])
print(pdf_value)
Drag options to blanks, or click blank then click option'
A0
B1
C-1
D0.5
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 or -1 which are not the peak points of the standard normal distribution.
Using 0.5 which is arbitrary and not the peak.
3fill in blank
hard

Fix the error in the code to generate 5 random samples from a normal distribution with mean 10 and standard deviation 2.

SciPy
from scipy.stats import norm

samples = norm.rvs(loc=[1], scale=2, size=5)
print(samples)
Drag options to blanks, or click blank then click option'
A2
B0
C5
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Setting loc to 2 which is the standard deviation, not the mean.
Setting loc to 0 or 5 which are incorrect for this distribution.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps numbers 1 to 5 to their normal PDF values with mean 0 and std 1, but only include values where PDF is greater than 0.2.

SciPy
pdf_dict = {x: norm.pdf(x, loc=[1], scale=[2]) for x in range(1, 6) if norm.pdf(x, loc=0, scale=1) > 0.2}
Drag options to blanks, or click blank then click option'
A0
B1
C2
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 for mean or 0 for std which reverses the parameters.
Using 2 or 5 which are not standard parameters.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps numbers 1 to 5 to their cumulative distribution function (CDF) values for a normal distribution with mean 5 and std 2, but only include values where CDF is less than 0.8.

SciPy
cdf_dict = {x: norm.[1](x, loc=[2], scale=[3]) for x in range(1, 6) if norm.cdf(x, loc=5, scale=2) < 0.8}
Drag options to blanks, or click blank then click option'
Acdf
B5
C2
Dpdf
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'pdf' instead of 'cdf' for cumulative probabilities.
Mixing up mean and std values.