W1 Assignment 3 In the backward_propagation_n

In the backward_propagation_n function
db1 = 4. / m * np.sum(dZ1, axis=1, keepdims=True) ← why db1 is 4. /m instead of 1./m?
Many thks

To show you how Gradient Checking works.

What do you mean?
If I have 1 instead of 4 what is changing?
And why only on db1?

Go ahead and complete Exercise 4 - gradient_check_n. You will get your answer.

1 Like

I have edited the first post and the title of this thread to correct the function name to backward_propagation_n.

Btw, @Luca_De_Renzo, that was a nice catch indeed :wink: . Hope you will find the text description after the gradient_check_n make sense!

Cheers,
Raymond

I have another catch
dW2 = 1. / m * np.dot(dZ2, A1.T) * 2 ← why is *2

I do not think I have to reshape right?
What can I do?

Hello @Luca_De_Renzo,

You do not have to reshape. What you can do is to read the error message and make sense of it. From the error message, if you look at “line 38” where the arrow has pointed to, there are three variables, figure out each of their shapes, and then see which two had the mismatching shapes (47, 1) and (1). After you figure out which two, then ask yourself why you would code them together as it is. Your understanding of what that step is doing should help you through the error.

Cheers,
Raymond

Nice catch as well. But the fact that you have asked why seems to indicate that you have not yet read the text description below the gradient_check_n function. Read it and you will see why it is there.

Yes, that is what I just typed.

Theta_plus [i] should be already a vector or not?
Why the error is giving me 47,1 as if it was a matrix
You intend instead that
theta_plus[i]= 47
theta_plus= 1
epsilon= 1

Hey @Luca_De_Renzo,

Print their shapes out.

I tried but won’t give anything… it giving me only the error

Add the print lines before the line that triggers the error. Don’t add them after the line that triggers the error, because you won’t get passed the line that triggers the error.

I cannot because I call a variable before I define it, am I wrong?

Did you add the print lines between line 37 and line 38?

How is it possible? Anyway
Is everything like the error said
theta_plus[i]= 47.1
theta_plus= 1,
epsilo= 1,
I have to take theta_plus[i] [1]?

Go to line 37, hit “Enter”, add the print lines.

1 Like

I intended

theta_plus[i][0]

Now, what is the shape of theta_plus and what is the shape of theta_plus[i]?