Complete the code to create a 2D NumPy array filled with zeros.
import numpy as np arr = np.[1]((3, 4))
The np.zeros function creates an array filled with zeros.
Complete the code to check if the array is stored in C-contiguous order.
is_c_contiguous = arr.[1]The flags.c_contiguous attribute tells if the array is stored in C-contiguous order (row-major).
Fix the error in the code to reshape the array without copying data.
reshaped = arr.[1]((6, 2), order='K')
The reshape method can reshape an array without copying data if possible, especially with order='K'.
Fill both blanks to create a Fortran-contiguous array and check its memory layout.
arr_f = np.array([[1, 2], [3, 4]], order=[1]) is_fortran = arr_f.flags.[2]
Setting order='F' creates a Fortran-contiguous array. The flags.f_contiguous attribute checks this layout.
Fill all three blanks to create a C-contiguous array, reshape it, and verify the layout.
arr_c = np.array([[5, 6], [7, 8]], order=[1]) reshaped_c = arr_c.[2]((4, 1)) is_c = reshaped_c.flags.[3]
Creating with order='C' makes a C-contiguous array. Using reshape changes shape without copying. The flags.c_contiguous confirms C-contiguity.