Recall & Review
beginner
What does it mean when a NumPy operation returns a view instead of a copy?
A view means the new array shares the same data in memory as the original array. Changes to the view affect the original array and vice versa.
Click to reveal answer
beginner
How can you create a true copy of a NumPy array?
Use the
copy() method on the array, like arr.copy(). This creates a new array with its own data in memory.Click to reveal answer
intermediate
What is the difference between shallow copy and deep copy in NumPy?
A shallow copy creates a new array object but shares the data buffer (like a view). A deep copy duplicates both the array object and the data buffer (like
copy()).Click to reveal answer
beginner
Why might slicing a NumPy array not create a copy?
Slicing usually creates a view to save memory and time. It does not copy data but references the original array's data.
Click to reveal answer
intermediate
How can you check if a NumPy array owns its data or is a view?
Check the
base attribute. If arr.base is None, the array owns its data. Otherwise, it is a view referencing another array.Click to reveal answer
What does
arr.copy() do in NumPy?✗ Incorrect
arr.copy() creates a new array with a separate copy of the data, so changes to the copy do not affect the original.
If you slice a NumPy array like
arr[1:4], what is usually returned?✗ Incorrect
Slicing usually returns a view that shares data with the original array to save memory.
How can you tell if a NumPy array is a view or owns its data?
✗ Incorrect
If arr.base is None, the array owns its data; otherwise, it is a view.
What happens if you modify a view of a NumPy array?
✗ Incorrect
Since a view shares data with the original array, changes to the view affect the original array as well.
Which method creates a deep copy of a NumPy array?
✗ Incorrect
arr.copy() creates a deep copy with its own data buffer.
Explain the difference between a view and a copy in NumPy arrays.
Think about memory sharing and data changes.
You got /4 concepts.
Describe how to check if a NumPy array owns its data or is a view.
Look at the array's base attribute.
You got /3 concepts.