# Exercise 6 - backward\_propagation in Programming Assignment Week 3

**URL:** <https://community.deeplearning.ai/t/exercise-6-backward-propagation-in-programming-assignment-week-3/221994>\
**Category:** Neural Networks and Deep Learning\
**Tags:** coursera-platform\
**Created:** [October 25, 2022, 2:56am UTC](https://community.deeplearning.ai/t/exercise-6-backward-propagation-in-programming-assignment-week-3/221994 "2022-10-25T02:56:38Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shiori\_YAMASHITA](https://avatars.discourse-cdn.com/v4/letter/s/b9bd4f/32.png) [@Shiori\_YAMASHITA](https://community.deeplearning.ai/u/Shiori_YAMASHITA)\
**Post date:** [October 25, 2022, 2:56am UTC](https://community.deeplearning.ai/t/exercise-6-backward-propagation-in-programming-assignment-week-3/221994/1 "2022-10-25T02:56:38Z")

</div>

In this markdown, Figure 1 shows

dZ2 = A2 - Y  
dW2 = (1/m) dZ2 A1.T

I think dZ2 = (1/m) (A2 - Y), dW2 = dZ2 A1.T. Is that correct? I’m sorry if I made a mistake in calculation.

---

<div class="post-metadata">

**Author:** ![Kic](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/kic/32/76339_2.png) [@Kic](https://community.deeplearning.ai/u/Kic)\
**Post date:** [October 25, 2022, 9:50am UTC](https://community.deeplearning.ai/t/exercise-6-backward-propagation-in-programming-assignment-week-3/221994/2 "2022-10-25T09:50:04Z")

</div>

Hi @Shiori_YAMASHITA

Not sure what your query is, could you please provide more details.

---

<div class="post-metadata">

**Author:** ![Shiori\_YAMASHITA](https://avatars.discourse-cdn.com/v4/letter/s/b9bd4f/32.png) [@Shiori\_YAMASHITA](https://community.deeplearning.ai/u/Shiori_YAMASHITA)\
**Post date:** [October 25, 2022, 10:20am UTC](https://community.deeplearning.ai/t/exercise-6-backward-propagation-in-programming-assignment-week-3/221994/3 "2022-10-25T10:20:03Z")

</div>

My question is exactly the same as discussed in this thread.

> [@Week 3,4: Why isn't 1/m part of dz^\[L\]?](https://community.deeplearning.ai/t/week-3-4-why-isnt-1-m-part-of-dz-l/9443/1):
>
> The derivative of J is 1/m \* (a^[L] - y), but instead of putting 1/m here, the formulas in the slides multiply every dW and db by 1/m. Is there a reason for this? Placing the 1/m with the derivatives of the last layer works for the assignments and is mathematically correct, so it seems odd to write the formulas as they are in the slides.

In the DLS Course 1 week 3 and 4 video lessons or programming assignments, the differential equation of backpropagation is described as follows.  
dZ[L] = A[L] - Y  
dW[i] = (1/m) dZ[i] A[i-1].T  
db[i] = (1/m) np.sum(dZ[i], axis=1, keepdims=True) (1\<=i\<=L)

Specifically, they appear in the following situations:  
・All scenes dealing with backpropagation Vectrization in the lecture videos of the 3rd and 4th weeks  
It first appears in the blackboard around 7:30 in the video of [https://www.coursera.org/learn/neural-networks-deep-learning/lecture/Wh8NI/gradient-descent-for-neural-networks](https://www.coursera.org/learn/neural-networks-deep-learning/lecture/Wh8NI/gradient-descent-for-neural-networks)

・clarification-for-what-does-this-have-to-do-with-the-brain document for modifying the typo in the video of this section

・Exercise-6 backward\_propagation cell in Week3 programming assignment (when L=2)

・Some people say that the same formulas will appear in the Week 4 assignments (I haven’t done the Week 4 assignments yet, so I don’t know)

But I suspect that this backpropagation differential equation is a typo.  
Correctly,  
dZ[L] = (1/m) (A[L] - Y)  
dW[i] = dZ[i] A[i-1].T  
db[i] = np.sum(dZ[i], axis=1, keepdims=True) (1\<=i\<=L).

It seems that typographical errors have occurred in all the scenes I mentioned above, so please confirm.  
In particular, some of the people who did the Week 4 assignments claim that points will be deducted for writing logically correct formulas, so I would appreciate it if you could confirm it as soon as possible.

---

<div class="post-metadata">

**Author:** ![Shiori\_YAMASHITA](https://avatars.discourse-cdn.com/v4/letter/s/b9bd4f/32.png) [@Shiori\_YAMASHITA](https://community.deeplearning.ai/u/Shiori_YAMASHITA)\
**Post date:** [October 25, 2022, 1:13pm UTC](https://community.deeplearning.ai/t/exercise-6-backward-propagation-in-programming-assignment-week-3/221994/4 "2022-10-25T13:13:56Z")

</div>

postscript:  
I have solved the program assignments for Week4, but it seems that the trouble I mentioned earlier is occurring in the Exercise 7 - linear\_backward cell of Building\_your\_Deep\_Neural\_Network\_Step\_by\_Step.

def linear\_backward(dZ, cache): In the cell starting with

_{moderator edit - solution code removed}_

is considered an incorrect answer and an error is thrown in the assert statement.

---

<div class="post-metadata">

**Author:** ![Mubsi](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/mubsi/32/94983_2.png) [@Mubsi](https://community.deeplearning.ai/u/Mubsi)\
**Post date:** [October 25, 2022, 1:51pm UTC](https://community.deeplearning.ai/t/exercise-6-backward-propagation-in-programming-assignment-week-3/221994/5 "2022-10-25T13:51:16Z")

</div>

Hi @Shiori_YAMASHITA,

Are you implying that the equations shown in the figure are incorrect ? They are not.

---

<div class="post-metadata">

**Author:** ![Shiori\_YAMASHITA](https://avatars.discourse-cdn.com/v4/letter/s/b9bd4f/32.png) [@Shiori\_YAMASHITA](https://community.deeplearning.ai/u/Shiori_YAMASHITA)\
**Post date:** [October 25, 2022, 2:13pm UTC](https://community.deeplearning.ai/t/exercise-6-backward-propagation-in-programming-assignment-week-3/221994/6 "2022-10-25T14:13:51Z")

</div>

Hi, @Mubsi,  
What do you mean by “the equations shown in the figure”?

---

<div class="post-metadata">

**Author:** ![paulinpaloalto](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/paulinpaloalto/32/187_2.png) [@paulinpaloalto](https://community.deeplearning.ai/u/paulinpaloalto)\
**Post date:** [October 25, 2022, 3:12pm UTC](https://community.deeplearning.ai/t/exercise-6-backward-propagation-in-programming-assignment-week-3/221994/7 "2022-10-25T15:12:25Z")

</div>

As Mubsi says, the equations as written are correct. I answered on the other thread where you also asked this question. [Here’s an older thread](https://community.deeplearning.ai/t/week-3-wrong-formula-for-the-derivatives-dz-2-in-videos-and-notebook/189029) that also discusses this point.

For the specific chunk of code you show, you are not supplying the factor of \frac {1}{m}, so presumably you did it “your way” and included that in the dAL calculation at the outer layer. You may be able to get that to work if you make the adjustments throughout, but I think the better strategy is just to follow the way Prof Ng does it. That will just be simpler than trying to rewrite everything your way.

---

<div class="post-metadata">

**Author:** ![paulinpaloalto](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/paulinpaloalto/32/187_2.png) [@paulinpaloalto](https://community.deeplearning.ai/u/paulinpaloalto)\
**Post date:** [October 25, 2022, 3:26pm UTC](https://community.deeplearning.ai/t/exercise-6-backward-propagation-in-programming-assignment-week-3/221994/8 "2022-10-25T15:26:21Z")

</div>

Note that a generalization of the formulas shown will also be used in Week 4 where we finally get to full generality and can have any number of hidden layers. Prof Ng is consistent in doing it the same way there: he does everything with derivatlves of L until the final step at each layer of computing the dW^{[l]} and db^{[l]} as derivatives of J.

---

<div class="post-metadata">

**Author:** ![Shiori\_YAMASHITA](https://avatars.discourse-cdn.com/v4/letter/s/b9bd4f/32.png) [@Shiori\_YAMASHITA](https://community.deeplearning.ai/u/Shiori_YAMASHITA)\
**Post date:** [October 27, 2022, 10:16am UTC](https://community.deeplearning.ai/t/exercise-6-backward-propagation-in-programming-assignment-week-3/221994/9 "2022-10-27T10:16:39Z")

</div>

I understood what the formula means owing to you. Thanks!

Best,  
Shiori

2022年10月26日(水) 0:36 Paul Mielke via DeepLearning.AI \<[notifications@dlai.discoursemail.com](mailto:notifications@dlai.discoursemail.com)\>:
