【发布时间】:2020-04-24 15:09:05
【问题描述】:
我正在从头开始使用神经网络,当我尝试实现稳定的 sigmoid 函数时,numpy where 似乎表现得很奇怪。这里的两个函数都返回 RuntimeWarning: overflow 在 exp 中遇到:
#Original Function
def sigmoid(x):
return np.where(x >= 0, 1 / (1 + np.exp(-x)), np.exp(x) / (1 + np.exp(x)))
#Dummy function that is also misbehaving
def sigmoid(x):
return np.where(x>=0, 1 / (1 + np.exp(-x)), 0)
这是结果:
【问题讨论】:
-
where不会阻止对整个数组的评估。这是蟒蛇 -
我该如何解决这个问题?
-
可以抑制警告。或者
ufunc像np.exp有自己的where机制。您还可以在传递给函数之前将clipx值。
标签: python numpy debugging neural-network numpy-ndarray