Recall & Review
beginner
What is C-order memory layout in numpy arrays?
C-order means the array is stored row by row in memory. The last index changes fastest, like reading lines in a book from left to right, top to bottom.
Click to reveal answer
beginner
What is Fortran-order memory layout in numpy arrays?
Fortran-order means the array is stored column by column in memory. The first index changes fastest, like reading columns downwards before moving right.
Click to reveal answer
beginner
How do you create a numpy array with Fortran-order memory layout?
Use the argument `order='F'` when creating the array, for example: `np.array([[1,2],[3,4]], order='F')`.
Click to reveal answer
intermediate
Why does memory layout matter in numpy?
Memory layout affects speed of operations and compatibility with other libraries. Accessing data in the stored order is faster because of how computers read memory.
Click to reveal answer
intermediate
How can you check the memory layout of a numpy array?
Use the attributes `.flags['C_CONTIGUOUS']` and `.flags['F_CONTIGUOUS']`. They tell if the array is stored in C-order or Fortran-order respectively.
Click to reveal answer
In C-order memory layout, which index changes fastest?
✗ Incorrect
In C-order, the last index changes fastest because data is stored row-wise.
How do you specify Fortran-order when creating a numpy array?
✗ Incorrect
Use order='F' to create arrays with Fortran-order memory layout.
Which numpy attribute tells if an array is stored in C-order?
✗ Incorrect
The .flags['C_CONTIGUOUS'] attribute is True if the array is stored in C-order.
Why might you choose Fortran-order over C-order?
✗ Incorrect
Fortran-order is useful to match memory layout expected by Fortran-based libraries.
What happens if you access numpy array elements in a different order than their memory layout?
✗ Incorrect
Accessing elements out of memory order can slow down performance due to cache misses.
Explain the difference between C-order and Fortran-order memory layouts in numpy arrays.
Think about how you read a table: by rows or by columns.
You got /4 concepts.
Describe how to check and create numpy arrays with specific memory layouts.
Look at array creation parameters and array flags.
You got /2 concepts.