Recall & Review
beginner
What does it mean when a NumPy view shares memory with the original array?
It means that the view and the original array point to the same data in memory. Changing one will change the other.
Click to reveal answer
beginner
How can you create a view of a NumPy array?
You can create a view by slicing the array or using the
view() method.Click to reveal answer
beginner
What happens if you modify a view of a NumPy array?
Modifying the view changes the original array because they share the same memory.
Click to reveal answer
intermediate
How can you check if two NumPy arrays share the same memory?
Use the
np.shares_memory(array1, array2) function to check if they share memory.Click to reveal answer
intermediate
What is the difference between a view and a copy in NumPy?
A view shares memory with the original array, so changes affect both. A copy has its own memory, so changes do not affect the original.
Click to reveal answer
What does slicing a NumPy array usually return?
✗ Incorrect
Slicing a NumPy array usually returns a view that shares memory with the original array.
If you change a value in a NumPy view, what happens to the original array?
✗ Incorrect
Because views share memory with the original array, changes in the view affect the original.
Which function checks if two arrays share memory in NumPy?
✗ Incorrect
np.shares_memory() returns True if two arrays share the same memory.
What method can explicitly create a view of a NumPy array?
✗ Incorrect
The view() method creates a new view of the array sharing the same data.
Which statement is true about copies in NumPy?
✗ Incorrect
Copies have their own memory and do not affect the original array when changed.
Explain what happens when you modify a NumPy view and how it relates to the original array.
Think about how memory is shared between view and original.
You got /3 concepts.
Describe how to check if two NumPy arrays share the same memory and why this might be useful.
Consider when you want to avoid unintended changes.
You got /3 concepts.