Recall & Review
beginner
What is the memory layout of a NumPy array?
It is how the array elements are stored in the computer's memory, usually in a continuous block either row-wise (C order) or column-wise (Fortran order).
Click to reveal answer
beginner
What does 'C order' mean in NumPy array memory layout?
It means the array is stored row by row, like reading lines in a book. The last axis changes fastest.
Click to reveal answer
beginner
What does 'Fortran order' mean in NumPy array memory layout?
It means the array is stored column by column, like reading down columns in a spreadsheet. The first axis changes fastest.
Click to reveal answer
intermediate
How can you check if a NumPy array is stored in C order or Fortran order?
Use the attributes
arr.flags['C_CONTIGUOUS'] and arr.flags['F_CONTIGUOUS']. They return True if the array is stored in C or Fortran order respectively.Click to reveal answer
intermediate
Why does understanding array memory layout matter?
Because it affects speed of operations and memory usage. Accessing elements in the stored order is faster due to how computers read memory.
Click to reveal answer
In NumPy, which memory layout stores elements row-wise?
✗ Incorrect
C order means row-wise storage, where rows are stored one after another.
Which NumPy attribute tells you if an array is stored in Fortran order?
✗ Incorrect
arr.flags['F_CONTIGUOUS'] returns True if the array is stored in Fortran order.
Why is accessing elements in the stored memory order faster?
✗ Incorrect
Accessing elements in stored order uses CPU cache better, speeding up operations.
What does it mean if a NumPy array is neither C_CONTIGUOUS nor F_CONTIGUOUS?
✗ Incorrect
If neither flag is True, the array memory is not stored continuously in either C or Fortran order.
Which of these is NOT a common memory layout for NumPy arrays?
✗ Incorrect
Z order is not a standard memory layout for NumPy arrays.
Explain the difference between C order and Fortran order in NumPy array memory layout.
Think about how you read text lines versus columns in a spreadsheet.
You got /3 concepts.
Why is it important to know the memory layout of a NumPy array when writing efficient code?
Consider how computers read memory and cache data.
You got /3 concepts.