# Course 1, Week 3, Exercise 6 Back Propagation

I Exercise 6, the checker is telling me that i have a dimension mismatch. However, as you can see below:

1. I inserted print statements in front of the cited calculations - and these print statement confirm that i DO NOT have a dimension mismatch.
2. As you can see, my code executes and generates all the expected results correctly before the checker finds the dimension mismatch error.
Can you pls help me figure out what i am doing wrong?
(1, 3)
(1, 3)
dW1 = [[ 0.00301023 -0.00747267]
[ 0.00257968 -0.00641288]
[-0.00156892 0.003893 ]
[-0.00652037 0.01618243]]
db1 = [[ 0.00176201]
[ 0.00150995]
[-0.00091736]
[-0.00381422]]
dW2 = [[ 0.00078841 0.01765429 -0.00084166 -0.01022527]]
db2 = [[-0.16655712]]
(1, 3)
(1, 7)

ValueError Traceback (most recent call last)
in
7 print ("db2 = "+ str(grads[“db2”]))
8
----> 9 backward_propagation_test(backward_propagation)

~/work/release/W3A1/public_tests.py in backward_propagation_test(target)
175 ‘db2’: np.array([[-0.78032466]])}
176
→ 177 output = target(parameters, cache, X, Y)
178
179 assert type(output[“dW1”]) == np.ndarray, f"Wrong type for dW1. Expected: {np.ndarray}"

in backward_propagation(parameters, cache, X, Y)
47 print(str(A2.shape))
48 print(str(Y.shape))
—> 49 dZ2 = A2 - Y
50 dW2 = 1/m * np.dot(dZ2, A1.T)
51 db2 = 1/m * np.sum(dZ2, axis = 1, keepdims=True)

ValueError: operands could not be broadcast together with shapes (1,3) (1,7)

Expected output

dW1 = [[ 0.00301023 -0.00747267]
[ 0.00257968 -0.00641288]
[-0.00156892 0.003893 ]
[-0.00652037 0.01618243]]
db1 = [[ 0.00176201]
[ 0.00150995]
[-0.00091736]
[-0.00381422]]
dW2 = [[ 0.00078841 0.01765429 -0.00084166 -0.01022527]]
db2 = [[-0.16655712]]
All tests passed!

When the notebook throws an assert, you can trust that it is telling the truth.

The test which is throwing the assert is in the python file “public_tests.py”, in a function called test_backward_propagation().

The utility test cases use a different size of data set. You can open the utility file and read the test case it uses.

1 Like

How do i downlad the python file public_test.py? clearly my error is happening in this test case, and i fear i do not know python well enough to debut it.

Am i correct to assume that the dimension mismatch is in the line dZ2 = A2 - Y? Is it right for me to assume that i have a dimension mismatch between A2 and Y?

That’s what the error message says.

Go to the File menu and open the public_tests.py file.

I found my error – a very dumb typo – thank you very much.

2 Likes