# Week 2: propagate function error

**URL:** <https://community.deeplearning.ai/t/week-2-propagate-function-error/458095>\
**Category:** Neural Networks and Deep Learning\
**Tags:** coursera-platform\
**Created:** [September 29, 2023, 7:58am UTC](https://community.deeplearning.ai/t/week-2-propagate-function-error/458095 "2023-09-29T07:58:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mudit\_Tyagi](https://avatars.discourse-cdn.com/v4/letter/m/db5fbb/32.png) [@Mudit\_Tyagi](https://community.deeplearning.ai/u/Mudit_Tyagi)\
**Post date:** [September 29, 2023, 7:58am UTC](https://community.deeplearning.ai/t/week-2-propagate-function-error/458095/1 "2023-09-29T07:58:33Z")

</div>

def propagate(w, b, X, Y):  
m = X.shape[1]

```
A = sigmoid(np.dot(w.T, X) + b)
cost = np.sum((( - np.log(A)) * Y + (-np.log(1 - A))*(1 - Y)) / (m)

dw = np.dot(X, (A-Y).T) / m
db = np.sum(A-Y)/ m

cost = np.squeeze(np.array(cost))

grads = {"dw": dw,
         "db": db}

return grads, cost

```

output error →   
File “”, line 42  
dw = np.dot(X, (A-Y).T) / m  
^  
SyntaxError: invalid syntax

---

<div class="post-metadata">

**Author:** ![gent.spah](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/gent.spah/32/136423_2.png) [@gent.spah](https://community.deeplearning.ai/u/gent.spah)\
**Post date:** [September 29, 2023, 9:28am UTC](https://community.deeplearning.ai/t/week-2-propagate-function-error/458095/2 "2023-09-29T09:28:53Z")

</div>

Check the brackets in the line upwards, cost, they dont match!

---

<div class="post-metadata">

**Author:** ![Salomey\_Addo](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@Salomey\_Addo](https://community.deeplearning.ai/u/Salomey_Addo)\
**Post date:** [October 4, 2023, 9:43am UTC](https://community.deeplearning.ai/t/week-2-propagate-function-error/458095/3 "2023-10-04T09:43:08Z")

</div>

Sometimes it is confusing to me when to use matrix multiplication and when to use elementwise multiplication. I was using matrix multiplication to calculate the cost and I was getting inaccurate answers. I will reflect on my understanding. I know the difference is subtle 😃

---

<div class="post-metadata">

**Author:** ![Deepti\_Prasad](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/deepti_prasad/32/165831_2.png) [@Deepti\_Prasad](https://community.deeplearning.ai/u/Deepti_Prasad)\
**Post date:** [October 4, 2023, 9:49am UTC](https://community.deeplearning.ai/t/week-2-propagate-function-error/458095/4 "2023-10-04T09:49:40Z")

</div>

Can you please specify for which codes line your question pertains to?

you can mention in your comment if the code is not part of any grader cell.

Regards  
DP
