C3_W2_Lab 2_Exercise 2, help for error


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.

1 Like

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.

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

1 Like

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.

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.

  1. The test_sq_dist() function is in public_tests.py, which is imported from this cell in the notebook:

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

1 Like

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.

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

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

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

1 Like


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

1 Like

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

{moderator edit: code removed}

@Karolina_Kopec ,
Glad you figured it out.

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

@Charlotte_Dandurand, note also that your results shown in the OP are incorrect.

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.

Thank you. That was key !

1 Like

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?

See the FAQ.


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?

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.

1 Like

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

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.

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

Thanks, I had done that, 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’.

1 Like