# Week1 - assignment - Loss function error

**URL:** <https://community.deeplearning.ai/t/week1-assignment-loss-function-error/81810>\
**Category:** NLP with Classification and Vector Spaces\
**Tags:** week-module-1\
**Created:** [January 3, 2022, 2:44am UTC](https://community.deeplearning.ai/t/week1-assignment-loss-function-error/81810 "2022-01-03T02:44:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vijaya\_kumar\_eyunni](https://avatars.discourse-cdn.com/v4/letter/v/5daacb/32.png) [@vijaya\_kumar\_eyunni](https://community.deeplearning.ai/u/vijaya_kumar_eyunni)\
**Post date:** [January 3, 2022, 2:44am UTC](https://community.deeplearning.ai/t/week1-assignment-loss-function-error/81810/1 "2022-01-03T02:44:28Z")

</div>

I implemented gradientDescent function, but getting this error:

Wrong output for the loss function. Check how you are implementing the matrix multiplications.  
Expected: 0.6709497038162118.  
Got: 6.783954452541828.  
Wrong output for the loss function. Check how you are implementing the matrix multiplications.  
Expected: 6.5044107216556135.  
Got: 162.83776189572313.

This is my sigmoid implementation:  
if np.isscalar(z):  
h = 1 / (1 + np.exp(-z))  
else:  
h = np.exp(-z)  
for i in range(len(h)):  
h[i] = 1 / (1 + h[i])

---

<div class="post-metadata">

**Author:** ![reinoudbosch](https://avatars.discourse-cdn.com/v4/letter/r/22d042/32.png) [@reinoudbosch](https://community.deeplearning.ai/u/reinoudbosch)\
**Post date:** [January 6, 2022, 5:54pm UTC](https://community.deeplearning.ai/t/week1-assignment-loss-function-error/81810/2 "2022-01-06T17:54:58Z")

</div>

Hi bijaya\_kumar\_eyunni,

[numpy.exp](https://numpy.org/doc/stable/reference/generated/numpy.exp.html) calculates the exponential of all elements in the input array, so you don’t have to use a separate loop that may cause bugs.

---

<div class="post-metadata">

**Author:** ![Atef\_Yasser](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/atef_yasser/32/144152_2.png) [@Atef\_Yasser](https://community.deeplearning.ai/u/Atef_Yasser)\
**Post date:** [February 26, 2023, 11:04am UTC](https://community.deeplearning.ai/t/week1-assignment-loss-function-error/81810/3 "2023-02-26T11:04:50Z")

</div>

Hello **vijaya\_kumar\_eyunni**  
You mustn’t do this with **np.exp()** as It can handle with  
scalars or matrix  
I understand your idea but this can’t be here  
if you want to use this idea you can write it with math.exp() as it handles only with scalars not matrix and you

I wish If I could help  
Dear Atef,
