0
0
NumPydata~5 mins

np.random.rand() and random arrays in NumPy - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does np.random.rand() do?
It creates an array of random numbers between 0 and 1, with the shape you specify.
Click to reveal answer
beginner
How do you create a 2x3 array of random numbers using np.random.rand()?
Use np.random.rand(2, 3). This makes 2 rows and 3 columns of random numbers between 0 and 1.
Click to reveal answer
beginner
What range of values does np.random.rand() generate?
It generates numbers from 0 (inclusive) up to 1 (exclusive). So, numbers are always >= 0 and < 1.
Click to reveal answer
intermediate
How is np.random.rand() different from np.random.randn()?
np.random.rand() generates uniform random numbers between 0 and 1, while np.random.randn() generates numbers from a normal (bell curve) distribution centered at 0.
Click to reveal answer
beginner
Why might you use np.random.rand() in data science?
To create random samples or initialize arrays for simulations, testing algorithms, or creating random data for experiments.
Click to reveal answer
What does np.random.rand(4, 2) produce?
AA 4x2 array of random numbers between 0 and 1
BA 2x4 array of random integers
CA 4x2 array of zeros
DA 4x2 array of random numbers from a normal distribution
Which of these is true about numbers from np.random.rand()?
AThey follow a normal distribution
BThey are always between 0 and 1, including 1
CThey can be negative
DThey are always between 0 and 1, excluding 1
How to create a 1D array with 5 random numbers using np.random.rand()?
A<code>np.random.rand(1,5)</code>
B<code>np.random.rand(5)</code>
C<code>np.random.rand(5,1)</code>
D<code>np.random.rand()</code>
What is the difference between np.random.rand() and np.random.randint()?
ABoth generate floats
BBoth generate integers
C<code>rand()</code> generates floats, <code>randint()</code> generates integers
D<code>rand()</code> generates integers, <code>randint()</code> generates floats
If you want a 3D array of random numbers with shape (2, 3, 4), how do you call np.random.rand()?
A<code>np.random.rand(2, 3, 4)</code>
B<code>np.random.rand(3, 4, 2)</code>
C<code>np.random.rand(2*3*4)</code>
D<code>np.random.rand([2, 3, 4])</code>
Explain how to create a 2D array of random numbers between 0 and 1 using np.random.rand(). Include how to specify the shape.
Think about rows and columns as arguments.
You got /4 concepts.
    Describe the difference between np.random.rand() and np.random.randn() and when you might use each.
    Consider the shape of the number distribution.
    You got /4 concepts.