What is the output of the following code showing the strides of a 2D NumPy array?
import numpy as np arr = np.array([[1, 2, 3], [4, 5, 6]], dtype=np.int32) print(arr.strides)
Remember that strides show the number of bytes to step in each dimension.
The array has shape (2, 3) with dtype int32 (4 bytes). The stride for the first dimension is 3 elements * 4 bytes = 12 bytes. The stride for the second dimension is 4 bytes.
What is the output of the strides attribute after transposing the array?
import numpy as np arr = np.array([[1, 2, 3], [4, 5, 6]], dtype=np.int32) arr_t = arr.T print(arr_t.strides)
Transposing swaps the dimensions and their strides.
Transposing swaps the shape and strides. Original strides were (12, 4), so after transpose they become (4, 12).
Which option correctly describes the memory layout visualization of the following reshaped array?
import numpy as np arr = np.arange(6, dtype=np.int32) arr_reshaped = arr.reshape((2, 3)) print(arr_reshaped.strides)
Check the strides and how reshape affects memory layout.
Reshape does not change the memory layout if possible. The array is contiguous with strides (12, 4) meaning rows are stored one after another.
Which statement correctly describes the difference between C-contiguous and F-contiguous arrays in NumPy?
Think about how multi-dimensional arrays are stored in C and Fortran languages.
C-contiguous means rows are stored one after another (row-major order). F-contiguous means columns are stored one after another (column-major order).
Given the code below, why does arr.flags['C_CONTIGUOUS'] return False?
import numpy as np arr = np.arange(12).reshape((3,4)) arr_sliced = arr[:, ::2] print(arr_sliced.flags['C_CONTIGUOUS'])
Consider how slicing with steps affects memory layout.
Slicing with a step (like ::2) creates a view that skips elements, breaking the contiguous memory layout.