【发布时间】:2021-01-21 07:51:37
【问题描述】:
当我给出以下命令时,它会起作用:
W2 = np.array( [[ 0.00874286,-0.01293537,-0.00079741,0.00564486,0.01233471]])
b2=np.array([[0.]])
a=np.array([[11.2,11.0,12.7],[10.1,34.4,4.0],[9.0,7.9,6.6],[8.5,8.0,9.45,],[5.5,9.9,8.3]])
Z = np.dot(W2,a)+b2
print(1/(1+np.exp(-Z)))
输出为:
[[0.51897047 0.4531795 0.55224658]]
但是当我按照它给出它会产生错误:
Z = np.dot(parameters['W2'],A)+parameters['b2']
print(1/(1+np.exp(-Z)))
其中 A, parameters['W2], parameters['b2'] 是 numpy 数组并且具有浮点值。 输出为:
AttributeError Traceback (most recent call last)
AttributeError: 'float' object has no attribute 'exp'
The above exception was the direct cause of the following exception:
TypeError Traceback (most recent call last)
<ipython-input-26-dc868b05af37> in <module>()
3 Z = np.dot(parameters['W2'],A)+parameters['b2']
4 #A1,C=linear_sigmoid_forward(A, parameters['W2'],parameters['b2'])
----> 5 print(1/(1+np.exp(-Z)))
TypeError: loop of ufunc does not support argument 0 of type float which has no callable exp method
在这两种情况下,我都给出了 float numpy 数组,但在第二种情况下会产生错误。为什么???
【问题讨论】:
标签: python-3.x