【发布时间】:2020-06-27 09:54:50
【问题描述】:
正在计算成本,但面临 TypeError: cannot unpack non-iterable float object 的错误
#Compute cost
def compute_cost(A2,y,parameters):
m=y.shape[0]
logprobs = y*np.log(A2) + (1-y)*np.log(1-A2)
cost = -1/m*np.sum(logprobs)
cost = float(np.squeeze(cost)) # makes sure cost is the dimension we expect.
assert(isinstance(cost, float))
return cost
#Calling the function
A2, y, parameters =compute_cost(A2,y,parameters)
print("cost = " + str(compute_cost(A2, y, parameters)))
TypeError Traceback (most recent call last)
<ipython-input-533-089c3da0f833> in <module>
1 A2, y, parameters =compute_cost(A2,y,parameters)
2 print("cost = " + str(compute_cost(A2, y, parameters)))
TypeError: cannot unpack non-iterable float object
【问题讨论】: