0
0
NumPydata~5 mins

Generating random samples in NumPy - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Anumpy.random.choice()
Bnumpy.random.randint()
Cnumpy.random.normal()
Dnumpy.random.rand()
How do you generate 10 random integers from 5 to 15 inclusive using numpy?
Anumpy.random.randint(5, 15, size=10)
Bnumpy.random.randint(5, 16, size=10)
Cnumpy.random.randint(6, 15, size=10)
Dnumpy.random.randint(5, 14, size=10)
What does setting a seed with numpy.random.seed() do?
AChanges the distribution type
BGenerates more random numbers
CMakes random numbers predictable and reproducible
DClears all previous random numbers
Which function generates random samples from a normal distribution?
Anumpy.random.normal()
Bnumpy.random.uniform()
Cnumpy.random.randint()
Dnumpy.random.choice()
What parameter controls the number of samples generated in numpy random functions?
Asize
Bcount
Clength
Dnumber
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.