向后传播 – 渐变错误[Python]

我正在通过Andrew Ng新的深度学习Coursera课程,第2周.

我们应该实现逻辑回归算法.
我陷入渐变代码(dw) – 给我一个语法错误.

算法如下:

import numpy as np

def propagate(w, b, X, Y):
    m = X.shape[1]

    A = sigmoid(np.dot(w.T,X) + b )  # compute activation
    cost = -(1/m)*(np.sum(np.multiply(Y,np.log(A)) + np.multiply((1-Y),np.log(1-A)), axis=1)    

    dw =(1/m)*np.dot(X,(A-Y).T)
    db = (1/m)*(np.sum(A-Y))
    assert(dw.shape == w.shape)
    assert(db.dtype == float)
    cost = np.squeeze(cost)
    assert(cost.shape == ())

    grads = {"dw": dw,
             "db": db}

    return grads, cost

任何想法为什么我继续得到这种语法错误?

File "<ipython-input-1-d104f7763626>", line 32
    dw =(1/m)*np.dot(X,(A-Y).T)
     ^
SyntaxError: invalid syntax
在行cost = …中,您在结尾处缺少一个括号,或者只删除*后的一个:

# ...
cost = -(1/m)*np.sum(np.multiply(Y,np.log(A)) + np.multiply((1-Y),np.log(1-A)), axis=1)
# ...
相关文章
相关标签/搜索