0
0
NumPydata~10 mins

Setting random seed for reproducibility 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 set the random seed to 42 using numpy.

NumPy
import numpy as np
np.random.[1](42)
Drag options to blanks, or click blank then click option'
Arand
Brandom
Cshuffle
Dseed
Attempts:
3 left
💡 Hint
Common Mistakes
Using np.random.rand(42) instead of np.random.seed(42).
Forgetting to import numpy as np.
2fill in blank
medium

Complete the code to generate a random integer between 0 and 9 after setting the seed.

NumPy
import numpy as np
np.random.seed(123)
num = np.random.[1](10)
print(num)
Drag options to blanks, or click blank then click option'
Arandint
Brandom
Crand
Dchoice
Attempts:
3 left
💡 Hint
Common Mistakes
Using np.random.rand(10) which generates floats, not integers.
Using np.random.random(10) which is incorrect syntax.
3fill in blank
hard

Fix the error in the code to set the seed correctly before generating random numbers.

NumPy
import numpy as np
np.random.[1](7)
print(np.random.rand())
Drag options to blanks, or click blank then click option'
Aseed
Brandom
Cseed_value
Dseed()
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning a value to np.random.seed instead of calling it as a function.
Using np.random.seed() without an argument.
4fill in blank
hard

Fill both blanks to create a reproducible array of 5 random floats between 0 and 1.

NumPy
import numpy as np
np.random.[1](0)
arr = np.random.[2](5)
print(arr)
Drag options to blanks, or click blank then click option'
Aseed
Brand
Crandint
Drandom
Attempts:
3 left
💡 Hint
Common Mistakes
Using np.random.randint(5) which generates integers, not floats.
Not setting the seed before generating random numbers.
5fill in blank
hard

Fill all three blanks to set the seed, generate 3 random integers from 0 to 4, and print them.

NumPy
import numpy as np
np.random.[1](10)
numbers = np.random.[2](0, 5, [3])
print(numbers)
Drag options to blanks, or click blank then click option'
Aseed
Brandint
C3
Drand
Attempts:
3 left
💡 Hint
Common Mistakes
Using np.random.rand instead of randint for integers.
Forgetting to specify the size parameter.