Recall & Review
beginner
What does it mean for a NumPy array to be contiguous?
A contiguous NumPy array stores its data in a single, continuous block of memory. This means the elements are laid out one after another without gaps, which makes operations faster and memory access efficient.
Click to reveal answer
intermediate
What is the purpose of stride tricks in NumPy?
Stride tricks let you create new views of an array by changing how NumPy steps through the data in memory, without copying it. This helps to create sliding windows or reshape data efficiently.Click to reveal answer
beginner
How can you check if a NumPy array is contiguous?
You can check if an array is contiguous by using the attributes
arr.flags['C_CONTIGUOUS'] or arr.flags['F_CONTIGUOUS']. C_CONTIGUOUS means row-major order, and F_CONTIGUOUS means column-major order.Click to reveal answer
advanced
What happens if you use stride tricks incorrectly?
Using stride tricks incorrectly can lead to unexpected results or even crashes because you might access memory outside the array bounds. It’s important to ensure the new view respects the original data layout.
Click to reveal answer
beginner
Explain the difference between a view and a copy in NumPy.
A view shares the same data buffer as the original array but may have a different shape or strides. Changes to the view affect the original array. A copy creates a new array with its own data, so changes do not affect the original.
Click to reveal answer
Which attribute tells you if a NumPy array is stored in a continuous block of memory in row-major order?
✗ Incorrect
The 'C_CONTIGUOUS' flag is True if the array is stored in a continuous block of memory in row-major (C-style) order.
What does the stride of a NumPy array represent?
✗ Incorrect
Stride tells how many bytes NumPy moves in memory to go from one element to the next along each dimension.
What is a key benefit of using stride tricks in NumPy?
✗ Incorrect
Stride tricks allow creating new views of the data with different shapes or windows without copying the data.
If an array is not contiguous, what might happen when performing operations?
✗ Incorrect
Non-contiguous arrays can cause slower operations because memory access is less efficient.
Which function in NumPy can be used to create a sliding window view using stride tricks?
✗ Incorrect
The function 'sliding_window_view' creates a view of sliding windows over the array using stride tricks.
Describe what contiguous arrays are in NumPy and why they matter for performance.
Think about how data is stored in memory and how that affects speed.
You got /4 concepts.
Explain how stride tricks work and give an example of when you might use them.
Consider how you can look at the same data in different shapes without copying.
You got /4 concepts.