# C3\_W2\_Lab 2\_Exercise 2, help for error

**URL:** <https://community.deeplearning.ai/t/c3-w2-lab-2-exercise-2-help-for-error/342954>\
**Category:** Unsupervised Learning, Recommenders, Reinforcement\
**Tags:** week-module-2\
**Created:** [May 24, 2023, 6:34pm UTC](https://community.deeplearning.ai/t/c3-w2-lab-2-exercise-2-help-for-error/342954 "2023-05-24T18:34:09Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Charlotte\_Dandurand](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@Charlotte\_Dandurand](https://community.deeplearning.ai/u/Charlotte_Dandurand)\
**Post date:** [May 24, 2023, 6:34pm UTC](https://community.deeplearning.ai/t/c3-w2-lab-2-exercise-2-help-for-error/342954/1 "2023-05-24T18:34:09Z")

</div>

![Screenshot 2023-05-24 at 11.29.41](https://global.discourse-cdn.com/dlai/original/3X/0/e/0e91e183da0a6168a1351b932492e24763bdbe46.jpeg)

Hi,

I am very much hoping someone can help me find the solution to the error I am getting.  
I have attached a screenshot of the error.  
Thank you so very much 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:** [May 24, 2023, 7:48pm UTC](https://community.deeplearning.ai/t/c3-w2-lab-2-exercise-2-help-for-error/342954/2 "2023-05-24T19:48:22Z")

</div>

Every time you open the notebook, you have to run all of the cells starting from the top. That’s where all of the assets and packages are imported.

---

<div class="post-metadata">

**Author:** ![Charlotte\_Dandurand](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@Charlotte\_Dandurand](https://community.deeplearning.ai/u/Charlotte_Dandurand)\
**Post date:** [May 26, 2023, 3:07am UTC](https://community.deeplearning.ai/t/c3-w2-lab-2-exercise-2-help-for-error/342954/3 "2023-05-26T03:07:59Z")

</div>

Thank you TMosh. I have tried that, but unfortunately error does not solve. Any other thoughts?

---

<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:** [May 26, 2023, 4:33am UTC](https://community.deeplearning.ai/t/c3-w2-lab-2-exercise-2-help-for-error/342954/4 "2023-05-26T04:33:00Z")

</div>

I think if you run all the cells, it will solve that problem. There is evidence you have not run all of the cells:

1. I see that you have “import numpy as np” at the startof this graded function.  
 ![image](https://global.discourse-cdn.com/dlai/original/3X/1/c/1c6a1bc220bd11a04ff5cd3fd6ebff95e1738c8a.png)

That’s incorrect. That indicates you tried to run that cell without running all of the previous cells. Then you got an error and fixed it by adding an import there.

You don’t need to import numpy there, because it’s imported in the first cell in the notebook.  
 ![image](https://global.discourse-cdn.com/dlai/original/3X/3/a/3a8d62bef1a40a9673cf89024d0128ba84bf2ae4.png)

1. The test\_sq\_dist() function is in public\_tests.py, which is imported from this cell in the notebook:  
 ![image](https://global.discourse-cdn.com/dlai/original/3X/6/b/6bb3c0907fd03e471c3942160db7b8e735826a2f.png)

So if you run all of the cells every time you open the notebook, you will have all of the required assets.

---

<div class="post-metadata">

**Author:** ![Charlotte\_Dandurand](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@Charlotte\_Dandurand](https://community.deeplearning.ai/u/Charlotte_Dandurand)\
**Post date:** [May 26, 2023, 4:53am UTC](https://community.deeplearning.ai/t/c3-w2-lab-2-exercise-2-help-for-error/342954/5 "2023-05-26T04:53:41Z")

</div>

Hi Tmosh,  
Thank you for the reply. I really appreciate it. I have removed the import numpy line and ran several times from top to bottom all the cells. I still get the error.

 ![Screenshot 2023-05-25 at 21.51.03](https://global.discourse-cdn.com/dlai/original/3X/b/7/b769be79f8c2076f6249864256725cc691c06137.jpeg)  
 ![Screenshot 2023-05-25 at 21.50.52](https://global.discourse-cdn.com/dlai/original/3X/f/b/fb0f68968092fa40827144331407466c07178b63.jpeg)

Of note, I did get all tests passed above and still get the error.

 ![Screenshot 2023-05-25 at 21.52.44](https://global.discourse-cdn.com/dlai/original/3X/a/2/a2931e923bf6189df901408388e3f113354b55e3.png)

Any other thoughts on how to solve this ?  
Thank you very much,

---

<div class="post-metadata">

**Author:** ![Mujassim\_Jamal](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/mujassim_jamal/32/53828_2.png) [@Mujassim\_Jamal](https://community.deeplearning.ai/u/Mujassim_Jamal)\
**Post date:** [May 26, 2023, 5:51am UTC](https://community.deeplearning.ai/t/c3-w2-lab-2-exercise-2-help-for-error/342954/8 "2023-05-26T05:51:47Z")

</div>

> [@Charlotte\_Dandurand](#):
>
> Of note, I did get all tests passed above and still get the error.

By looking at the screenshot, this time it throws an AssertionError, which indicates that there is a fault in your function `sq_dist()`.

---

<div class="post-metadata">

**Author:** ![Karolina\_Kopec](https://avatars.discourse-cdn.com/v4/letter/k/f17d59/32.png) [@Karolina\_Kopec](https://community.deeplearning.ai/u/Karolina_Kopec)\
**Post date:** [May 26, 2023, 10:34am UTC](https://community.deeplearning.ai/t/c3-w2-lab-2-exercise-2-help-for-error/342954/9 "2023-05-26T10:34:40Z")

</div>

Hi!

I have exactly the same problem. The squared distance are different than expected…

---

<div class="post-metadata">

**Author:** ![Karolina\_Kopec](https://avatars.discourse-cdn.com/v4/letter/k/f17d59/32.png) [@Karolina\_Kopec](https://community.deeplearning.ai/u/Karolina_Kopec)\
**Post date:** [May 26, 2023, 10:49am UTC](https://community.deeplearning.ai/t/c3-w2-lab-2-exercise-2-help-for-error/342954/10 "2023-05-26T10:49:20Z")

</div>

I figured it out! The code is wrong. It should be:

{moderator edit: code removed}

---

<div class="post-metadata">

**Author:** ![Mujassim\_Jamal](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/mujassim_jamal/32/53828_2.png) [@Mujassim\_Jamal](https://community.deeplearning.ai/u/Mujassim_Jamal)\
**Post date:** [May 26, 2023, 11:30am UTC](https://community.deeplearning.ai/t/c3-w2-lab-2-exercise-2-help-for-error/342954/11 "2023-05-26T11:30:39Z")

</div>

@Karolina_Kopec ,  
Glad you figured it out.

Please remove your code. Posting code is not allowed as per the community guidelines.

---

<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:** [May 26, 2023, 3:18pm UTC](https://community.deeplearning.ai/t/c3-w2-lab-2-exercise-2-help-for-error/342954/12 "2023-05-26T15:18:55Z")

</div>

@Charlotte_Dandurand, note also that your results shown in the OP are incorrect.  
 ![image](https://global.discourse-cdn.com/dlai/original/3X/a/2/a269a617c77ad3407f4c85b6e0028f272f66e6a2.png)

Do the instructions tell you to use a square root function? The comments imply you should compute the “squared distance”. That would be the sum of the squares. No square root.

---

<div class="post-metadata">

**Author:** ![Charlotte\_Dandurand](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@Charlotte\_Dandurand](https://community.deeplearning.ai/u/Charlotte_Dandurand)\
**Post date:** [May 27, 2023, 5:09pm UTC](https://community.deeplearning.ai/t/c3-w2-lab-2-exercise-2-help-for-error/342954/13 "2023-05-27T17:09:02Z")

</div>

Thank you. That was key !

---

<div class="post-metadata">

**Author:** ![Zahra\_Lotfi](https://avatars.discourse-cdn.com/v4/letter/z/eada6e/32.png) [@Zahra\_Lotfi](https://community.deeplearning.ai/u/Zahra_Lotfi)\
**Post date:** [May 28, 2023, 12:08am UTC](https://community.deeplearning.ai/t/c3-w2-lab-2-exercise-2-help-for-error/342954/14 "2023-05-28T00:08:40Z")

</div>

Hi, I’m sorry, I’m stuck in this activity, that’s why all the codes are messed up, even the explanations of the questions are deleted, and the codes that worked before don’t work now. How can I start everything from the beginning?  
Thanks.

---

<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:** [May 28, 2023, 12:54am UTC](https://community.deeplearning.ai/t/c3-w2-lab-2-exercise-2-help-for-error/342954/15 "2023-05-28T00:54:24Z")

</div>

> [@Zahra\_Lotfi](#):
>
> How can I start everything from the beginning?

See the FAQ.

> [@FAQ: Frequently Asked Questions for all MLS Courses](https://community.deeplearning.ai/t/faq-frequently-asked-questions-for-all-mls-courses/184322):
>
> FAQ Hello learners, hope you find this FAQs helpful. If you have a specific question on course materials, please read [this FAQ](https://community.deeplearning.ai/t/faq-frequently-asked-questions-for-all-mls-courses/184322/6#i-need-help-on-course-meterials-what-should-i-do-22) first. A. Resources Download [Where can I download lecture slides?](https://community.deeplearning.ai/t/faq-frequently-asked-questions-for-all-mls-courses/184322/6#where-can-i-download-lecture-slides-2)[How can I backup my assignment labs or optional labs?](https://community.deeplearning.ai/t/faq-frequently-asked-questions-for-all-mls-courses/184322/6#how-can-i-backup-my-assignment-labs-or-optional-labs-3)B. Assignment / Optional Labs [:wrench: [Troubleshoot] Failed to open a lab and see the “Unable to open lab / Unable to retrieve a launch URL Error”](https://community.deeplearning.ai/t/faq-frequently-asked-questions-for-all-mls-courses/184322/6#troubleshoot-failed-to-open-a-lab-and-see-the-unable-to-open-lab-unable-to-retrieve-a-launch-url-error-4)[:wrench: [Troubleshoot] Failed to open a lab and see the “Your lab session has timed out…](https://community.deeplearning.ai/t/faq-frequently-asked-questions-for-all-mls-courses/184322/6#troubleshoot-failed-to-open-a-lab-and-see-the-your-lab-session-has-timed-out-message-5)

---

<div class="post-metadata">

**Author:** ![Zahra\_Lotfi](https://avatars.discourse-cdn.com/v4/letter/z/eada6e/32.png) [@Zahra\_Lotfi](https://community.deeplearning.ai/u/Zahra_Lotfi)\
**Post date:** [May 28, 2023, 1:13pm UTC](https://community.deeplearning.ai/t/c3-w2-lab-2-exercise-2-help-for-error/342954/16 "2023-05-28T13:13:18Z")

</div>

Hello again, I wrote the codes, even at the bottom of the answers, it says that the all tests passed, but I don’t know why it doesn’t give me a score. I also refreshed the device, but there is still no score in my grades section. Can anyone help me out?  
Thanks

---

<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:** [May 28, 2023, 6:16pm UTC](https://community.deeplearning.ai/t/c3-w2-lab-2-exercise-2-help-for-error/342954/17 "2023-05-28T18:16:11Z")

</div>

Passing the tests in the notebook do not prove your code is perfect.  
The grader tests your code using different data and conditions.

What feedback do you get from the grader? Please post a screen capture image.

---

<div class="post-metadata">

**Author:** ![Zahra\_Lotfi](https://avatars.discourse-cdn.com/v4/letter/z/eada6e/32.png) [@Zahra\_Lotfi](https://community.deeplearning.ai/u/Zahra_Lotfi)\
**Post date:** [May 28, 2023, 10:05pm UTC](https://community.deeplearning.ai/t/c3-w2-lab-2-exercise-2-help-for-error/342954/19 "2023-05-28T22:05:18Z")

</div>

okay thank you so much I corrected thanks:) I got my score thanks

---

<div class="post-metadata">

**Author:** ![Martin\_Talke](https://avatars.discourse-cdn.com/v4/letter/m/f14d63/32.png) [@Martin\_Talke](https://community.deeplearning.ai/u/Martin_Talke)\
**Post date:** [September 19, 2023, 5:14pm UTC](https://community.deeplearning.ai/t/c3-w2-lab-2-exercise-2-help-for-error/342954/20 "2023-09-19T17:14:37Z")

</div>

Hi Karolina, could you give a hint how you solved it? Have the same issue as it was here, but you seemed to have solved it and then the discussion stopped.

---

<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:** [September 19, 2023, 5:29pm UTC](https://community.deeplearning.ai/t/c3-w2-lab-2-exercise-2-help-for-error/342954/21 "2023-09-19T17:29:11Z")

</div>

> [@Martin\_Talke](#):
>
> and then the discussion stopped

Use np.sum() and np.square() of the differences.

---

<div class="post-metadata">

**Author:** ![Martin\_Talke](https://avatars.discourse-cdn.com/v4/letter/m/f14d63/32.png) [@Martin\_Talke](https://community.deeplearning.ai/u/Martin_Talke)\
**Post date:** [September 19, 2023, 7:52pm UTC](https://community.deeplearning.ai/t/c3-w2-lab-2-exercise-2-help-for-error/342954/22 "2023-09-19T19:52:14Z")

</div>

Thanks, I had done that, but it only calculate a1 and b1 correctly and not a2/b2 and a3/b3.

---

<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:** [September 19, 2023, 7:55pm UTC](https://community.deeplearning.ai/t/c3-w2-lab-2-exercise-2-help-for-error/342954/23 "2023-09-19T19:55:17Z")

</div>

> [@Martin\_Talke](#):
>
> but it only calculate a1 and b1 correctly and not a2/b2 and a3/b3.

What are are a1, a2, b1, and b2? The function we’re discussing only uses two vectors ‘a’ and ‘b’.

[Next page](https://community.deeplearning.ai/t/c3-w2-lab-2-exercise-2-help-for-error/342954.md?page=2)
