You just give the same list x1
another name: x2
that bot point to the same data. modifying one is modifying the data that the other one points to as well.
You need to (shallow) copy:
import numpy as np
def reluDerivative(yy):
return [0 if x <=0 else 1 for x in yy ]
x1 = np.random.uniform(-1, 1,10)
x2 = x1.copy() # copy of x1, no longer same data
x1[0] = 2 # proves decoupling of x1 and x2
x3 = reluDerivative(x2)
print(x1, x2, x3)
Output:
[2. 0.84077008 -0.30286357 -0.26964574 0.3979045 -0.8478326
-0.4056378 0.16776436 0.55790904 0.3550891 ]
[-0.00736343 0.84077008 -0.30286357 -0.26964574 0.3979045 -0.8478326
-0.4056378 0.16776436 0.55790904 0.3550891 ]
[0, 1, 0, 0, 1, 0, 0, 1, 1, 1]