Recall & Review
beginner
What function in numpy is commonly used to generate random samples from a uniform distribution?
The function
numpy.random.rand() generates random samples from a uniform distribution over [0, 1).Click to reveal answer
beginner
How do you generate 5 random integers between 10 and 20 using numpy?
Use
numpy.random.randint(10, 21, size=5). It generates 5 integers from 10 (inclusive) to 21 (exclusive), so 10 to 20.Click to reveal answer
beginner
What does the
size parameter control in numpy random sampling functions?The
size parameter controls how many random samples you want to generate. For example, size=3 returns 3 samples.Click to reveal answer
intermediate
How can you set a seed in numpy to get reproducible random samples?
Use
numpy.random.seed(your_number) before generating samples. This makes sure you get the same random numbers every time you run the code.Click to reveal answer
intermediate
Which numpy function would you use to generate random samples from a normal (Gaussian) distribution?
Use
numpy.random.normal(loc=0.0, scale=1.0, size=None). It generates samples from a normal distribution with mean loc and standard deviation scale.Click to reveal answer
Which numpy function generates random floats between 0 and 1?
✗ Incorrect
numpy.random.rand() generates random floats uniformly between 0 and 1.
How do you generate 10 random integers from 5 to 15 inclusive using numpy?
✗ Incorrect
The upper bound in numpy.random.randint() is exclusive, so use 16 to include 15.
What does setting a seed with
numpy.random.seed() do?✗ Incorrect
Setting a seed makes the random numbers the same every time you run the code.
Which function generates random samples from a normal distribution?
✗ Incorrect
numpy.random.normal() generates samples from a normal (Gaussian) distribution.
What parameter controls the number of samples generated in numpy random functions?
✗ Incorrect
The size parameter sets how many random samples to generate.
Explain how to generate 5 random integers between 1 and 10 using numpy. Include how to make the results reproducible.
Think about the function for integers and how to fix randomness.
You got /4 concepts.
Describe the difference between numpy.random.rand() and numpy.random.normal(). When would you use each?
Consider the shape of the data each function produces.
You got /3 concepts.