Complete the code to create a zero-filled array of length 5.
import numpy as np arr = np.[1](5) print(arr)
The np.zeros() function creates an array filled with zeros. Here, it creates an array of length 5 filled with zeros.
Complete the code to create a 2x3 zero-filled array.
import numpy as np arr = np.zeros([1]) print(arr)
The shape argument for np.zeros() is a tuple or list indicating the dimensions. Here, [2, 3] creates 2 rows and 3 columns.
Fix the error in the code to create a zero-filled array of shape (4, 4).
import numpy as np arr = np.zeros([1]) print(arr)
The shape argument must be a single tuple. So np.zeros((4, 4)) is correct. Using separate arguments or other brackets causes errors.
Fill both blanks to create a zero-filled array of integers with shape (3, 2).
import numpy as np arr = np.zeros([1], dtype=[2]) print(arr)
float instead of int for dtype.The shape must be a tuple like (3, 2). The dtype argument sets the data type; int makes the array hold integers.
Fill all three blanks to create a zero-filled 3D array with shape (2, 3, 4) and float data type.
import numpy as np arr = np.zeros([1], dtype=[2], order=[3]) print(arr.shape, arr.dtype)
int instead of float for dtype.'F' order without understanding memory layout.The shape is a tuple with three dimensions: (2, 3, 4). The dtype is float for floating-point zeros. The order 'C' means row-major order, which is common.