0
0
NumPydata~10 mins

Uniform random with random() in NumPy - 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 a single random number between 0 and 1 using numpy.

NumPy
import numpy as np
random_number = np.random.[1]()
Drag options to blanks, or click blank then click option'
Arandom
Brandint
Cchoice
Drandn
Attempts:
3 left
💡 Hint
Common Mistakes
Using randint which returns integers.
Using randn which returns numbers from a normal distribution.
2fill in blank
medium

Complete the code to generate an array of 5 random floats between 0 and 1.

NumPy
import numpy as np
random_array = np.random.[1](5)
Drag options to blanks, or click blank then click option'
Arandom
Bchoice
Crandint
Drandn
Attempts:
3 left
💡 Hint
Common Mistakes
Using randint which returns integers.
Using randn which returns normally distributed numbers.
3fill in blank
hard

Fix the error in the code to generate a 2x3 array of random floats between 0 and 1.

NumPy
import numpy as np
random_matrix = np.random.random([1])
Drag options to blanks, or click blank then click option'
A[2,3]
B(2,3)
C{2,3}
D2,3
Attempts:
3 left
💡 Hint
Common Mistakes
Passing shape as separate arguments instead of a tuple.
Using square brackets instead of parentheses.
4fill in blank
hard

Fill both blanks to create a dictionary with words as keys and their random scores between 0 and 1 as values.

NumPy
import numpy as np
words = ['apple', 'banana', 'cherry']
scores = {word: np.random.[1]() for word in [2]
Drag options to blanks, or click blank then click option'
Arandom
Brandint
Cwords
Drange(3)
Attempts:
3 left
💡 Hint
Common Mistakes
Using randint which generates integers.
Iterating over range(3) instead of the words list.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase words as keys and random scores greater than 0.5 as values.

NumPy
import numpy as np
words = ['dog', 'cat', 'bird']
result = {word.[1](): np.random.random() for word in words if np.random.random() [2] 0.5 and word [3] 'cat'}
Drag options to blanks, or click blank then click option'
Aupper
B>
C!=
Dlower
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'lower' instead of 'upper'.
Using '==' instead of '!=' to exclude 'cat'.