I use python3.9 where I declared a variable x, which is an input to function output = model(x). After the call x gets the same values as output variable. I expected that x before and after call should be the same, but it is not. The code behaves as if the output variable and local variables in the function model are pointers to x. Could you kindly explain this behavior? I've never met anything like that in Fortran, C/C++ and Matlab. Here is an example of my python code
import numpy as np
def model(aux):
for i in range(0,len(aux)):
aux[i] = np.sin( aux[i] ) + 1
return aux
length = 5
x = np.linspace(0,1,length)
print(' X variable BEFORE the function call ')
print(x)
output = model(x)
print(' X variable AFTER the function call ')
print(x)
print(' Output variable AFTER the function call ')
print(output)
Ad here is what I get:
X variable BEFORE the function call
[0. 0.25 0.5 0.75 1. ]
X variable AFTER the function call
[1. 1.24740396 1.47942554 1.68163876 1.84147098]
Output variable AFTER the function call
[1. 1.24740396 1.47942554 1.68163876 1.84147098]
Shouldn't X variable BEFORE and AFTER be the same?