So I have a question that pertains to the scope of variables in functions in python, consider the following code:
import numpy as np
def function(data, mask):
data *= mask
data = np.ones(5)
for x in range(2):
print(data)
mask = np.array([1, 0, 0, 0, 0])
function(data, mask)
And the output is the following:
[1. 1. 1. 1. 1.]
[1. 0. 0. 0. 0.]
My question is why data changes after the first iteration? I always thought that the local variable of a function was... local, so any modification would remain confined within the scope of the function. Clearly I was wrong. Is this because data in the function is still referencing the same object as the data in the global scope?