Complete the code to create a NumPy array with C-order memory layout.
import numpy as np arr = np.array([[1, 2], [3, 4]], order=[1]) print(arr.flags['C_CONTIGUOUS'])
Using order='C' creates the array with C-order (row-major) memory layout.
Complete the code to create a NumPy array with Fortran-order memory layout.
import numpy as np arr = np.array([[1, 2], [3, 4]], order=[1]) print(arr.flags['F_CONTIGUOUS'])
Using order='F' creates the array with Fortran-order (column-major) memory layout.
Fix the error in the code to check if an array is stored in C-order.
import numpy as np arr = np.array([[1, 2], [3, 4]], order='C') print(arr.flags[[1]])
The correct flag to check C-order memory layout is 'C_CONTIGUOUS'.
Fill both blanks to create a Fortran-order array and check its memory layout.
import numpy as np arr = np.array([[1, 2], [3, 4]], order=[1]) print(arr.flags[[2]])
Use order='F' to create a Fortran-order array and check with 'F_CONTIGUOUS' flag.
Fill all three blanks to create a C-order array, reshape it, and check if it remains C-contiguous.
import numpy as np arr = np.array([1, 2, 3, 4], order=[1]) arr_reshaped = arr.reshape((2, 2), order=[2]) print(arr_reshaped.flags[[3]])
Creating and reshaping with order='C' keeps the array C-contiguous, checked by 'C_CONTIGUOUS' flag.