Recall & Review
beginner
What does 'contiguous memory layout' mean in numpy arrays?
It means the array's data is stored in one continuous block of memory without gaps, making access faster and more efficient.
Click to reveal answer
beginner
How can you check if a numpy array has a contiguous memory layout?
Use the attribute
array.flags['C_CONTIGUOUS'] or array.flags['F_CONTIGUOUS'] to check if the array is contiguous in C or Fortran order.Click to reveal answer
intermediate
Why is contiguous memory layout important for numpy array operations?
Because it allows numpy to access data quickly in loops and vectorized operations, improving speed and reducing memory overhead.
Click to reveal answer
intermediate
What numpy function can you use to make a non-contiguous array contiguous?
You can use
numpy.ascontiguousarray() to create a contiguous copy of an array if it is not already contiguous.Click to reveal answer
intermediate
What is the difference between C-contiguous and F-contiguous arrays in numpy?
C-contiguous arrays store data row-wise (last index changes fastest), while F-contiguous arrays store data column-wise (first index changes fastest).
Click to reveal answer
Which numpy attribute tells you if an array is stored in contiguous memory?
✗ Incorrect
The 'flags' attribute with 'C_CONTIGUOUS' key shows if the array is stored in contiguous memory in C order.
What does numpy.ascontiguousarray() do?
✗ Incorrect
It returns a contiguous array copy if the input is not already contiguous.
Why is contiguous memory layout faster for numpy operations?
✗ Incorrect
Contiguous memory improves speed by allowing efficient cache access and vectorized operations.
Which order does a C-contiguous numpy array follow?
✗ Incorrect
C-contiguous arrays store data row-wise, meaning the last index changes fastest.
If an array is not contiguous, what might happen during numpy operations?
✗ Incorrect
Non-contiguous arrays can cause slower operations because data is not stored in a single block.
Explain what contiguous memory layout means in numpy and why it matters for performance.
Think about how data is stored in memory and how that affects access speed.
You got /3 concepts.
Describe how to check if a numpy array is contiguous and how to make it contiguous if it is not.
Look at numpy array attributes and functions related to memory layout.
You got /2 concepts.