小编Egb*_*ert的帖子

ReLU衍生物与NumPy

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变量?

python arrays numpy activation-function relu

3
推荐指数
1
解决办法
2191
查看次数

标签 统计

activation-function ×1

arrays ×1

numpy ×1

python ×1

relu ×1