AssertionError: Wrong values for grads['dw']

Hello, I’m stuck at this error in the Matrix version of my code.

AssertionError: Wrong values for grads[‘dw’].
[[-0.00154399] [-0.00492761]] != [[0.99845601] [2.39507239]]

To debug, I wrote the below longhand sample and it also returns the exact same result as the Matrix version of the code. Best part is I already completed this assignment ~4 months ago (then got sidetracked due to work) and that Matrix code is once again identical to my latest Matrix code, with 1 critical difference. The input Y is defined as [[1, 0, 1]] (instead of [[1, 1, 0]] as in the latest assignment). If I use Y [[1, 0, 1]], I get the dw result that the assertion is looking for. Would like to understand what is the mistake I am making. My file from 4 months ago is also in my Coursera drive as Logistic_Regression_with_a_Neural_Network_mindset_2021_10_10_01_16_32.ipynb
…and it passed all checks, and the prior submission was successful. Is this new Y desired value a typo?

w = np.array([[1.], [2.]])
b = 2.
X = np.array([[1., 2., -1.], [3., 4., -3.2]])
Y = np.array([[1, 1, 0]])

z = X[0,0] * w[0,0] + X[1,0] * w[1,0] + b
yh0 = sigmoid(z)
dz0 = yh0 - Y[0,0]
dw00 = dz0 * X[0,0]
dw01 = dz0 * X[1,0]
db0 = dz0
print(z, yh0, dz0, dw00, dw01, db0)

z = X[0,1] * w[0,0] + X[1,1] * w[1,0] + b
yh1 = sigmoid(z)
dz1 = yh1 - Y[0,1]
dw10 = dz1 * X[0,1]
dw11 = dz1 * X[1,1]
db1 = dz1
print(z, yh1, dz1, dw10, dw11, db1)

z = X[0,2] * w[0,0] + X[1,2] * w[1,0] + b
yh2 = sigmoid(z)
dz2 = yh2 - Y[0,2]
dw20 = dz2 * X[0,2]
dw21 = dz2 * X[1,2]
db2 = dz2
print(z, yh2, dz2, dw20, dw21, db2)

dw0 = 1/3 * (dw00 + dw10 + dw20)
dw1 = 1/3 * (dw01 + dw11 + dw21)
print(dw0, dw1)

Hi, I met a same bug, with a same wrong value of dw.

According to your post, I tried to reset the value of Y in propagate function, like ‘Y = np.array([[1, 0, 1]])’. Then I passed all tests.

So I think you are right, it’s a input typo.

Hi All,

I am also facing the same problem, I have checked calculations, But not able to debug where I am doing it wrong for dw and db calculation. I am following
dw = dj/dw = (A-Y)X
np.dot((A-Y),X.T).T is the code line which I have used but I think somewhere wrong code.
The value of A is correct and also cost function value correct.
A is [[0.99979657 0.62245933 0.00273196]]
dw = [[ 0.75214595]
[-0.19812289]]
db = -0.37501213501318953
cost = 0.15900537707692405
A is [[0.99849882 0.99979657 0.15446527 0.99966465]]

Kindly help in resolving issue.

Thanks & Regards
Suhas Gupta