Lesson 16
Views vs Copies
Slicing = view (shared memory). Use .copy() for independence:
c = a[1:4].copy() c[0] = 999 # a unchanged
Why this matters
This lesson prevents silent bugs: mutating a slice and accidentally corrupting the original array is one of the most common NumPy footguns.
The same idea shows up in pandas .loc and chained-assignment gotchas.
ResourcesDocs, references & more โ opens in a new tab
๐ฏ Your Task
original = [10,20,30,40,50]. Copy [1:4] โ safe_slice. Set [0]=999. Verify original unchanged.
safe_slice = original[1:4].copy()
โโ run ยท โโ โ nav
โถ Output
Run your code to see output here.