As you can guess by the title I'm not quite sure how to ask this question. Anyway the problem is the following:
I want to pass a numpy array as a parameter to a function, inside this function I want to make a copy of that array, then pass the array to another function manipulating the array and in the end replace the array with the copy.
...
arr = np.array([...])
arr_ocp = arr.copy()
func1(arr)
print np.array_equal(arr,arr_ocp) -> False
...
def func1(arr):
arr_cp = arr.copy()
func2(arr)
print np.array_equal(arr,arr_cp) -> False
arr = arr_cp
print np.array_equal(arr,arr_cp) -> True
def func2(arr):
...
arr[x:x+l,y:y+w] += np.array(...)
...
Now i did a few prints and it turns out that in func1 arr is the same at the beginning and the end, which I'd have expected.But if I do a print after func1(arr), arr is now the value of arr after func2. So why do the manipulations of func2 apply to arr but not the arr = arr_cp?
In hindsight it's probably better to pass the copy to func2 instead of the array itself, still I'd not expect this to happen like this. Am I missing something here?
prints with the actual output?prints, so I can understand the problem