0
0
NumPydata~5 mins

Garbage collection and array references in NumPy - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What happens to a NumPy array when all references to it are deleted?
The array's memory is freed by Python's garbage collector because no references remain to it.
Click to reveal answer
beginner
How does assigning one NumPy array to another variable affect memory?
Both variables point to the same array in memory; no new array is created unless explicitly copied.
Click to reveal answer
beginner
What method can you use to create a separate copy of a NumPy array to avoid shared references?
Use the copy() method, e.g., new_array = old_array.copy().
Click to reveal answer
intermediate
Why is it important to understand references when working with NumPy arrays?
Because modifying one variable can change the array seen by another variable if they share the same reference.
Click to reveal answer
intermediate
How does Python's garbage collector know when to free a NumPy array's memory?
It tracks reference counts; when the count drops to zero, the memory is released.
Click to reveal answer
If you assign b = a where a is a NumPy array, what happens?
A<code>b</code> points to the same array as <code>a</code>.
BA new array is created and stored in <code>b</code>.
CThe array is deleted from memory.
DPython raises an error.
Which method creates a new independent copy of a NumPy array?
A<code>array.duplicate()</code>
B<code>array.assign()</code>
C<code>array.clone()</code>
D<code>array.copy()</code>
What triggers Python's garbage collector to free a NumPy array's memory?
AWhen the array is explicitly deleted with <code>del</code>.
BWhen no references to the array remain.
CWhen the array is larger than 1GB.
DWhen the program ends.
If you modify a NumPy array through one variable, what happens to other variables referencing the same array?
AThey see the updated changes.
BThey keep the old values.
CThey raise an error.
DThey become None.
Which of the following is NOT true about NumPy array references?
AMultiple variables can point to the same array.
BUsing <code>copy()</code> creates a new array in memory.
CAssigning one array to another variable copies the data automatically.
DGarbage collection frees arrays with zero references.
Explain how Python's garbage collection works with NumPy arrays and why references matter.
Think about how Python tracks variables pointing to the same array.
You got /4 concepts.
    Describe the difference between assigning a NumPy array to a new variable and creating a copy of it.
    Consider what happens in memory and when you change the array.
    You got /4 concepts.