import numpy as np arr = np.arange(12).reshape(3,4) print(arr.flags['C_CONTIGUOUS'])
The reshape method by default returns a view with a contiguous memory layout in C order (row-major). So the C_CONTIGUOUS flag is True.
import numpy as np arr = np.arange(6).reshape(2,3) arr_t = arr.T print(arr_t.flags['C_CONTIGUOUS'])
Transposing an array returns a view with a different memory layout, which is not contiguous in C order. Hence, C_CONTIGUOUS is False.
import numpy as np arr = np.arange(10) sliced = arr[::2] print(len(sliced), sliced.flags['C_CONTIGUOUS'])
The slice arr[::2] selects every second element, resulting in 5 elements. This view is not contiguous in memory, so C_CONTIGUOUS is False.
import numpy as np arr = np.arange(6).reshape(2,3) arr_slice = arr[:, 1:3] print(arr_slice.flags)
The slice arr[:, 1:3] returns a view that is contiguous in C order because columns are contiguous in each row. So C_CONTIGUOUS is True and F_CONTIGUOUS is False. The array does not own its data (OWNDATA is False).
Contiguous memory means data is stored one after another. This helps the CPU cache to load data efficiently, speeding up computations. Other options are incorrect because they describe unrelated or false effects.