为了快速计算,我必须在 Numpy 中实现我的 sigmoid 函数,这是下面的代码
def sigmoid(Z):
"""
Implements the sigmoid activation in bumpy
Arguments:
Z -- numpy array of any shape
Returns:
A -- output of sigmoid(z), same shape as Z
cache -- returns Z, useful during backpropagation
"""
cache=Z
print(type(Z))
print(Z)
A=1/(1+(np.exp((-Z))))
return A, cache
还有一些相关信息:
Z=(np.matmul(W,A)+b)
Z 的类型为:
<class 'numpy.ndarray'>
遗憾的是,我得到了:“一元操作数类型错误 -:‘元组’”
我试图解决这个问题,但没有任何运气。我感谢任何建议。
最好的
这对我有用。我认为不需要使用缓存,因为你已经初始化了它。尝试下面的代码。
import matplotlib.pyplot as plt
import numpy as np
z = np.linspace(-10, 10, 100)
def sigmoid(z):
return 1/(1 + np.exp(-z))
a = sigmoid(z)
plt.plot(z, a)
plt.xlabel("z")
plt.ylabel("sigmoid(z)")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)