Complete the code to create a 1D array of 5 random numbers between 0 and 1 using numpy.
import numpy as np random_array = np.random.[1](5) print(random_array)
The np.random.rand() function generates random numbers between 0 and 1. Here, rand(5) creates an array of 5 such numbers.
Complete the code to create a 2D array with 3 rows and 4 columns of random numbers between 0 and 1.
import numpy as np array_2d = np.random.[1](3, 4) print(array_2d)
rand.randint which generates integers.np.random.rand(3, 4) creates a 2D array with 3 rows and 4 columns filled with random floats between 0 and 1.
Fix the error in the code to generate a 1D array of 10 random floats between 0 and 1.
import numpy as np random_numbers = np.random.rand([1]) print(random_numbers)
range(10) which is not accepted.The np.random.rand() function expects dimensions as separate integer arguments, not a list or tuple. So, rand(10) creates a 1D array of length 10.
Fill both blanks to create a dictionary where keys are numbers 1 to 5 and values are their random floats between 0 and 1.
import numpy as np random_dict = {i: np.random.[1]() for i in range(1, [2])} print(random_dict)
randint which generates integers.np.random.rand() generates a random float between 0 and 1. The range goes up to 6 to include numbers 1 through 5.
Fill all three blanks to create a 3x3 numpy array of random floats and print its shape and type.
import numpy as np arr = np.random.[1]([2], [3]) print(arr.shape) print(type(arr))
randint which generates integers.np.random.rand(3, 3) creates a 3 by 3 array of random floats between 0 and 1. The shape prints as (3, 3) and the type is numpy.ndarray.