Complete the code to create a 3x3 array filled with the number 7 using np.full().
import numpy as np array = np.full((3, 3), [1]) print(array)
The np.full() function creates an array of the given shape filled with the specified value. Here, we want to fill the array with 7.
Complete the code to create a 2x4 array filled with the string 'hi' using np.full().
import numpy as np array = np.full((2, 4), [1], dtype=str) print(array)
To fill the array with the string 'hi', pass it as the fill value to np.full(). The dtype=str ensures the array holds strings.
Fix the error in the code to create a 4x2 array filled with 0.5 using np.full().
import numpy as np array = np.full([1], 0.5) print(array)
The shape argument must be a tuple, so use parentheses (4, 2). Lists or other types cause errors.
Fill both blanks to create a 3x3 array filled with the integer 9 and print its data type.
import numpy as np array = np.full([1], [2], dtype=int) print(array.dtype)
The first blank is the shape tuple (3, 3). The second blank is the fill value 9. The dtype is set to int to store integers.
Fill all three blanks to create a 2x5 array filled with 3.14, specify float type, and print the array shape.
import numpy as np array = np.full([1], [2], dtype=[3]) print(array.shape)
The shape is (2, 5), the fill value is 3.14, and the dtype is float to store decimal numbers.