# Week 2 Exercise 5 propagate function

**URL:** <https://community.deeplearning.ai/t/week-2-exercise-5-propagate-function/22948>\
**Category:** Neural Networks and Deep Learning\
**Tags:** coursera-platform\
**Created:** [July 23, 2021, 11:48pm UTC](https://community.deeplearning.ai/t/week-2-exercise-5-propagate-function/22948 "2021-07-23T23:48:15Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![mfagre](https://avatars.discourse-cdn.com/v4/letter/m/0ea827/32.png) [@mfagre](https://community.deeplearning.ai/u/mfagre)\
**Post date:** [July 26, 2021, 4:08am UTC](https://community.deeplearning.ai/t/week-2-exercise-5-propagate-function/22948/21 "2021-07-26T04:08:42Z")

</div>

Hi!

I have the same problem with the results of exercise 5. I’m getting these results even after updating to the latest version:

dw = [[-0.00154399]  
[-0.00492761]]  
db = 0.0014555781367842193  
cost = 0.0015453193941501516  
All tests passed!

These results don’t match the expected values.

Thank you in advance.

---

<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:** [July 26, 2021, 4:29am UTC](https://community.deeplearning.ai/t/week-2-exercise-5-propagate-function/22948/22 "2021-07-26T04:29:20Z")

</div>

I added a print statement in my _propagate_ code to show the A and m values. Here’s what I see on the test cell for _propagate_:

```auto
m = 3
A = [[0.99979657 0.62245933 0.00273196]]
dw = [[0.25071532]
 [-0.06604096]]
db = -0.1250040450043965
cost = 0.15900537707692405
m = 4
A = [[0.99849882 0.99979657 0.15446527 0.99966465]]
All tests passed!

```

There must be some problem with your code. Notice that all your values have much smaller absolute values than my results and all of them include the factor of \frac {1}{m}. Are your A and m values the same as what I show above?

---

<div class="post-metadata">

**Author:** ![mfagre](https://avatars.discourse-cdn.com/v4/letter/m/0ea827/32.png) [@mfagre](https://community.deeplearning.ai/u/mfagre)\
**Post date:** [July 26, 2021, 5:12pm UTC](https://community.deeplearning.ai/t/week-2-exercise-5-propagate-function/22948/23 "2021-07-26T17:12:53Z")

</div>

Dear @paulinpaloalto, thank you very much for your answer. As you mentioned there was an error in my code. Fortunately, I was able to figure it out. Thank you for your help!

---

<div class="post-metadata">

**Author:** ![ongr1996](https://avatars.discourse-cdn.com/v4/letter/o/d26b3c/32.png) [@ongr1996](https://community.deeplearning.ai/u/ongr1996)\
**Post date:** [July 27, 2021, 1:15pm UTC](https://community.deeplearning.ai/t/week-2-exercise-5-propagate-function/22948/25 "2021-07-27T13:15:43Z")

</div>

Hi @paulinpaloalto , I am having a problem with the propagate function as well and I have also been getting the same outputs those being:

dw = [[-0.00154399]  
[-0.00492761]]  
db = 0.0014555781367842193  
cost = 0.0015453193941501516

The thing that has been confusing me is that my A and m do not match. For the A values before applying sigmoid I have a 1x3 , I have [[9. 12. -5.4]] and after A = [[0.99987661 0.99999386 0.00449627]]. Is there something I am misunderstanding here with the operations. I thought I was taking the dot product of w.T, a 1x2 (w is a 2x1) with X which is a 2x3 to get 1x3. After getting the dot product, I broadcast the bias which was 2f in the tests. And I can call the sigmoid function or rewrite the sigmoid function, and apply the sigmoid to that vector to get A.

As for m which is provided as m = X.shape[1]. I thought m is the number of examples, is that correct? m is given by the prompt and when I print m, I get the 3. But I noticed, your m increases from 3 to 4.

---

<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:** [July 27, 2021, 2:55pm UTC](https://community.deeplearning.ai/t/week-2-exercise-5-propagate-function/22948/26 "2021-07-27T14:55:23Z")

</div>

Hi, Ryan.

That just means you have the old version of the notebook. I added the logic to also print out my Z values

Z = w^T \cdot X + b

before computing A and here’s what I get for the _propagate_ test cell:

```auto
m = 3
Z = [[8.5 0.5 -5.9]]
A = [[0.99979657 0.62245933 0.00273196]]
dw = [[0.25071532]
 [-0.06604096]]
db = -0.1250040450043965
cost = 0.15900537707692405
m = 4
Z = [[6.5 8.5 -1.7 8.]]
A = [[0.99849882 0.99979657 0.15446527 0.99966465]]
All tests passed!

```

The point is that second test (the one from _public\_tests.py_) has also changed in the latest version of the notebook. It has m = 4 and some different input values. You need to use the “get a clean copy” procedure from the [FAQ Thread](https://community.deeplearning.ai/t/frequently-asked-questions/74) to get the latest version. Note that you need to delete the file _public\_tests.py_ before you do the “Get Latest Version”, so that you pick up the new version of that file which has the fix in addition to the notebook file itself. You need to move the notebook file aside (as described in the instructions) and then “copy/paste” over your work to the new copy.

The instructions are pretty clear that the “Get Latest Version” procedure will never overwrite an existing file, so you need to move your version of the notebook aside and also delete all the utility files (the dot py files) you see when you click “File → Open” in order to get the updates.

The other big topic here is how “updates” work when the course staff publishes a new or fixed version of something. They can publish any given update either as a “forced update” or not. I think they usually used “forced” updates, so you get it without any action on your part. Then you need to recover any of your work from the saved copy of the notebook that they moved aside (the date will be interpolated into the name) and saved for you. So it looks like they must have published the latest fix as a “self paced” fix that you have to ask for. Well, either that or there is something about your situation that I don’t understand.

---

<div class="post-metadata">

**Author:** ![ongr1996](https://avatars.discourse-cdn.com/v4/letter/o/d26b3c/32.png) [@ongr1996](https://community.deeplearning.ai/u/ongr1996)\
**Post date:** [July 29, 2021, 9:31am UTC](https://community.deeplearning.ai/t/week-2-exercise-5-propagate-function/22948/27 "2021-07-29T09:31:50Z")

</div>

Thank you very much for the assistance, you were correct, it was just a matter of updating the public\_tests.

---

<div class="post-metadata">

**Author:** ![prachee](https://avatars.discourse-cdn.com/v4/letter/p/ba8739/32.png) [@prachee](https://community.deeplearning.ai/u/prachee)\
**Post date:** [July 29, 2021, 3:07pm UTC](https://community.deeplearning.ai/t/week-2-exercise-5-propagate-function/22948/28 "2021-07-29T15:07:49Z")

</div>

I get a traceback error: ValueError: shapes (1,3) and (1,3) not aligned: 3 (dim 1) != 1 (dim 0). I would appreciate any insights. Thank you.

---

<div class="post-metadata">

**Author:** ![sr1349](https://avatars.discourse-cdn.com/v4/letter/s/f17d59/32.png) [@sr1349](https://community.deeplearning.ai/u/sr1349)\
**Post date:** [July 30, 2021, 10:11am UTC](https://community.deeplearning.ai/t/week-2-exercise-5-propagate-function/22948/29 "2021-07-30T10:11:47Z")

</div>

I am getting this error, how to fix it ???

![Screenshot 2021-07-30 154126](https://global.discourse-cdn.com/dlai/original/2X/6/6ba36c361023cf17bb81a39b34e59cf71db9f243.png)

---

<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:** [July 31, 2021, 2:25pm UTC](https://community.deeplearning.ai/t/week-2-exercise-5-propagate-function/22948/30 "2021-07-31T14:25:45Z")

</div>

If you are going to use the dot product to compute the cost, it requires that you transpose the second operand. [Here’s a thread](https://community.deeplearning.ai/t/week3-programming-assignment-4-4-compute-the-cost/18646/6) which shows some examples of the techniques that can be used.

---

<div class="post-metadata">

**Author:** ![prachee](https://avatars.discourse-cdn.com/v4/letter/p/ba8739/32.png) [@prachee](https://community.deeplearning.ai/u/prachee)\
**Post date:** [August 1, 2021, 2:39am UTC](https://community.deeplearning.ai/t/week-2-exercise-5-propagate-function/22948/31 "2021-08-01T02:39:09Z")

</div>

Thank you! I understand it better now.

---

<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:** [August 1, 2021, 8:42am UTC](https://community.deeplearning.ai/t/week-2-exercise-5-propagate-function/22948/32 "2021-08-01T08:42:26Z")

</div>

The value you show does look like it is a 64 bit floating point value. Please print the type you are actually getting and see what it is. E.g. try adding this print statement to your code in _propagate_:

`print(f"type(db) = {type(db)}")`

When I run the test case for _propagate_ with that statement in place, here’s what I get:

```auto
type(db) = <class 'numpy.float64'>
dw = [[0.25071532]
 [-0.06604096]]
db = -0.1250040450043965
cost = 0.15900537707692405

```

Of course that passes the assertion as written. What do you see for the type?

---

<div class="post-metadata">

**Author:** ![StefanRamdhan](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@StefanRamdhan](https://community.deeplearning.ai/u/StefanRamdhan)\
**Post date:** [August 12, 2021, 5:07am UTC](https://community.deeplearning.ai/t/week-2-exercise-5-propagate-function/22948/33 "2021-08-12T05:07:53Z")

</div>

@paulinpaloalto @andres.castillo I am getting this same assertion error due to the public\_tests.py checking against the wrong inputs.

What do you mean by you need to “forceRefresh” to get the fix working? I have tried refreshing the page, restarting the Kernel, and typing in “forceRefresh()” and “forceRefresh” into a cell, but I am still getting this assertion error on the side of the developer. What can I do to get this working?

---

<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:** [August 12, 2021, 3:16pm UTC](https://community.deeplearning.ai/t/week-2-exercise-5-propagate-function/22948/34 "2021-08-12T15:16:13Z")

</div>

There is a topic on the [FAQ Thread](https://community.deeplearning.ai/t/faq-frequently-asked-questions-for-dls-course-1/74) that explains how to get a clean copy of the notebook and the associated files.

---

<div class="post-metadata">

**Author:** ![lilArunav](https://avatars.discourse-cdn.com/v4/letter/l/7c8e57/32.png) [@lilArunav](https://community.deeplearning.ai/u/lilArunav)\
**Post date:** [August 21, 2021, 7:41am UTC](https://community.deeplearning.ai/t/week-2-exercise-5-propagate-function/22948/35 "2021-08-21T07:41:56Z")

</div>

I am getting the same Assertion Error and for the type I am getting :  
type(db) = \<class ‘numpy.ndarray’\>

Attaching the SS of my code

_{moderator edit - solution code removed}_

---

<div class="post-metadata">

**Author:** ![lilArunav](https://avatars.discourse-cdn.com/v4/letter/l/7c8e57/32.png) [@lilArunav](https://community.deeplearning.ai/u/lilArunav)\
**Post date:** [August 21, 2021, 7:42am UTC](https://community.deeplearning.ai/t/week-2-exercise-5-propagate-function/22948/36 "2021-08-21T07:42:59Z")

</div>

I tried using np.float64 too , but it doesn’t change the type.  
I also tried using np.dot()

I can’t figure out where the error is occuring

---

<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:** [August 21, 2021, 11:04am UTC](https://community.deeplearning.ai/t/week-2-exercise-5-propagate-function/22948/37 "2021-08-21T11:04:39Z")

</div>

Your cost calculation is wrong. You are dotting a 1 x m array with a scalar, which will give you a 1 x m array as the output if I am reading the code correctly. Also db should be a scalar. You need an _np.sum_ there.

---

<div class="post-metadata">

**Author:** ![HridayAg0102](https://avatars.discourse-cdn.com/v4/letter/h/7bcc69/32.png) [@HridayAg0102](https://community.deeplearning.ai/u/HridayAg0102)\
**Post date:** [September 6, 2021, 6:29pm UTC](https://community.deeplearning.ai/t/week-2-exercise-5-propagate-function/22948/38 "2021-09-06T18:29:49Z")

</div>

@paulinpaloalto , could you tell how can I get the newer version of this notebook , this problem has wasted a lot of my time and I am not sure how this would be configured

please respond as soon as possible

---

<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:** [September 6, 2021, 6:35pm UTC](https://community.deeplearning.ai/t/week-2-exercise-5-propagate-function/22948/39 "2021-09-06T18:35:07Z")

</div>

There is a topic about that on the [FAQ Thread](https://community.deeplearning.ai/t/faq-frequently-asked-questions-for-dls-course-1/74).

---

<div class="post-metadata">

**Author:** ![HridayAg0102](https://avatars.discourse-cdn.com/v4/letter/h/7bcc69/32.png) [@HridayAg0102](https://community.deeplearning.ai/u/HridayAg0102)\
**Post date:** [September 6, 2021, 6:51pm UTC](https://community.deeplearning.ai/t/week-2-exercise-5-propagate-function/22948/40 "2021-09-06T18:51:38Z")

</div>

Thank you sir , it worked

---

<div class="post-metadata">

**Author:** ![antontveretin](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@antontveretin](https://community.deeplearning.ai/u/antontveretin)\
**Post date:** [September 10, 2021, 11:37am UTC](https://community.deeplearning.ai/t/week-2-exercise-5-propagate-function/22948/41 "2021-09-10T11:37:30Z")

</div>

Just an insight. I don’t want to spoil. I held ValueError: shapes (1,3) and (1,3) not aligned for some time.  
np.dot is element-wise multiplication (or np.multiply) followed by np.sum. Sometimes it is better to do it explicitly.  
Error corrected, test passed.

[Previous page](https://community.deeplearning.ai/t/week-2-exercise-5-propagate-function/22948.md?page=1)

[Next page](https://community.deeplearning.ai/t/week-2-exercise-5-propagate-function/22948.md?page=3)
