import numpy as np
def relu(z):
return np.maximum(0,z)
def d_relu(z):
z[z>0]=1
z[z<=0]=0
return z
x=np.array([5,1,-4,0])
y=relu(x)
z=d_relu(y)
print("y = {}".format(y))
print("z = {}".format(z))
Run Code Online (Sandbox Code Playgroud)
上面的代码输出:
y = [1 1 0 0]
z = [1 1 0 0]
Run Code Online (Sandbox Code Playgroud)
代替
y = [5 1 0 0]
z = [1 1 0 0]
Run Code Online (Sandbox Code Playgroud)
据我了解,我使用过的函数调用只应该按值传递,传递变量的副本。
为什么我的d_relu函数会影响y变量?