19/26
Part 3 of 4 · Picking entries out of a tableLearn and do

A slice is a window, not a copy

A plain slice like square[0] is a window onto the same numbers, not a copy. Write into it and the table changes too:

table = square.copy()
# a window onto Ana's row
ana = table[0]
ana[:] = 0
print(table)
[[  0   0   0]
 [ 50 100  60]
 [ 80  70  75]]

So a function that writes into its input changes the caller's array. table.copy() above made a real copy first, so square is untouched. np.where(mask, a, b) also builds a new array and leaves its inputs alone.

In the editor, drop_test1(x) sets test 1 to 0 for everyone. Fill in its first line so it writes into a copy and leaves the caller's table alone. The last line prints square, so you can see whether it changed.