# Issue with last assigment of Neural Networks and Deep Learning course

**URL:** <https://community.deeplearning.ai/t/issue-with-last-assigment-of-neural-networks-and-deep-learning-course/493772>\
**Category:** Neural Networks and Deep Learning\
**Tags:** coursera-platform\
**Created:** [November 13, 2023, 9:37pm UTC](https://community.deeplearning.ai/t/issue-with-last-assigment-of-neural-networks-and-deep-learning-course/493772 "2023-11-13T21:37:34Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![naif\_asswiel](https://avatars.discourse-cdn.com/v4/letter/n/65b543/32.png) [@naif\_asswiel](https://community.deeplearning.ai/u/naif_asswiel)\
**Post date:** [November 13, 2023, 9:37pm UTC](https://community.deeplearning.ai/t/issue-with-last-assigment-of-neural-networks-and-deep-learning-course/493772/1 "2023-11-13T21:37:34Z")

</div>

hi guys,  
actually i h have problem with the last assigment of the first course in this specialization

i have issue with two\_layer\_model function  
i have this error

ndexError Traceback (most recent call last)  
 in   
1 parameters, costs = two\_layer\_model(train\_x, train\_y, layers\_dims = (n\_x, n\_h, n\_y), num\_iterations = 2, print\_cost=False)  
2  
----\> 3 print("Cost after first iteration: " + str(costs[0]))  
4  
5 two\_layer\_model\_test(two\_layer\_model)

IndexError: list index out of range

can any one help me

---

<div class="post-metadata">

**Author:** ![akanfah\_Ishmael](https://avatars.discourse-cdn.com/v4/letter/a/d78d45/32.png) [@akanfah\_Ishmael](https://community.deeplearning.ai/u/akanfah_Ishmael)\
**Post date:** [November 13, 2023, 9:50pm UTC](https://community.deeplearning.ai/t/issue-with-last-assigment-of-neural-networks-and-deep-learning-course/493772/2 "2023-11-13T21:50:26Z")

</div>

Dm let’s learn together +233558020084 I’m also taking that course

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/tmosh/32/9321_2.png) [@TMosh](https://community.deeplearning.ai/u/TMosh)\
**Post date:** [November 13, 2023, 10:32pm UTC](https://community.deeplearning.ai/t/issue-with-last-assigment-of-neural-networks-and-deep-learning-course/493772/3 "2023-11-13T22:32:32Z")

</div>

The error suggests that `costs[0]` is not valid. Are you certain that `costs` is a vector?

---

<div class="post-metadata">

**Author:** ![naif\_asswiel](https://avatars.discourse-cdn.com/v4/letter/n/65b543/32.png) [@naif\_asswiel](https://community.deeplearning.ai/u/naif_asswiel)\
**Post date:** [November 14, 2023, 3:12pm UTC](https://community.deeplearning.ai/t/issue-with-last-assigment-of-neural-networks-and-deep-learning-course/493772/4 "2023-11-14T15:12:52Z")

</div>

i should mention that i have tis bug since two months almost  
normaly i dont have any syntaxe bugs in the code but here is  
actually for the list costs i dont have any acess to the first element here is the code.

_{moderator edit: code removed}_

… and here is the code of the assignment

parameters, costs = two\_layer\_model(train\_x, train\_y, layers\_dims = (n\_x, n\_h, n\_y), num\_iterations = 2, print\_cost=False)

print("Cost after first iteration: " + str(costs[0]))

two\_layer\_model\_test(two\_layer\_model)

and here is the error 🈶  
IndexError Traceback (most recent call last)  
 in   
1 parameters, costs = two\_layer\_model(train\_x, train\_y, layers\_dims = (n\_x, n\_h, n\_y), num\_iterations = 2, print\_cost=False)  
2  
----\> 3 print("Cost after first iteration: " + str(costs[0]))  
4  
5 two\_layer\_model\_test(two\_layer\_model)

IndexError: list index out of range

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/tmosh/32/9321_2.png) [@TMosh](https://community.deeplearning.ai/u/TMosh)\
**Post date:** [November 14, 2023, 3:45pm UTC](https://community.deeplearning.ai/t/issue-with-last-assigment-of-neural-networks-and-deep-learning-course/493772/5 "2023-11-14T15:45:53Z")

</div>

There is no syntax error. There is a runtime error though. This is a fairly easy problem to debug if you follow the evidence.

If print\_cost is False, then your code for costs.append(cost) never runs. It’s inside an if-statement that tests print\_cost.

Did you perhaps modify this line of code in the notebook? Because print\_cost shouldn’t be used there.  
 ![image](https://global.discourse-cdn.com/dlai/original/3X/1/8/182ee4db5f8131786912dec284c07c02a52aa350.png)

---

<div class="post-metadata">

**Author:** ![naif\_asswiel](https://avatars.discourse-cdn.com/v4/letter/n/65b543/32.png) [@naif\_asswiel](https://community.deeplearning.ai/u/naif_asswiel)\
**Post date:** [November 14, 2023, 10:19pm UTC](https://community.deeplearning.ai/t/issue-with-last-assigment-of-neural-networks-and-deep-learning-course/493772/6 "2023-11-14T22:19:31Z")

</div>

yeah i think that i have modified the code by mistake  
so could you send me the right version of cide tò submit  
i thank you in advance

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/tmosh/32/9321_2.png) [@TMosh](https://community.deeplearning.ai/u/TMosh)\
**Post date:** [November 14, 2023, 10:31pm UTC](https://community.deeplearning.ai/t/issue-with-last-assigment-of-neural-networks-and-deep-learning-course/493772/7 "2023-11-14T22:31:56Z")

</div>

Here is how it should look:  
 ![image](https://global.discourse-cdn.com/dlai/original/3X/1/4/14e74cff838e82724257eec819f543a7692db336.png)

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/tmosh/32/9321_2.png) [@TMosh](https://community.deeplearning.ai/u/TMosh)\
**Post date:** [November 14, 2023, 10:33pm UTC](https://community.deeplearning.ai/t/issue-with-last-assigment-of-neural-networks-and-deep-learning-course/493772/8 "2023-11-14T22:33:06Z")

</div>

If you need a new copy of the notebook, you can get that via the instructions in the DLS FAQ. You can find it in the DLS Resources area, by using the forum search tool.

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/tmosh/32/9321_2.png) [@TMosh](https://community.deeplearning.ai/u/TMosh)\
**Post date:** [November 14, 2023, 10:35pm UTC](https://community.deeplearning.ai/t/issue-with-last-assigment-of-neural-networks-and-deep-learning-course/493772/9 "2023-11-14T22:35:14Z")

</div>

Note that I have edited this thread to remove your code - sharing your code is not allowed by the Code of Conduct.
