Week 1 - Practice Lab 1 'error'

Hi, I’m currently doing the first practice lab from the Week 1/Course 3 however I’m facing an error with the function ‘find_closest_centroids’ as the image shows.


Could someone help me please?!

Thanks =D.

Hi @Gabrielle_Navarro ,

Click on the hint to access the guidance on how to code this function. It also helps to locate where the problem of your code lies.

1 Like


The result of your method seems to be the default values of the idx array, all 0s.
Are you assigning the closest centroids to the idx array?

Yes, I’m. I even used the code on the hints and the same mistaken happen =(.

Can you send me your code in a direct message and I’ll take a look

Hi @Gabrielle_Navarro ,

The problem is the line of code for calculating the index for the min distance. Your code is outside of the ‘for’ loops. It should be within the 1st code block of the ‘for’ loop. Please check the hint.

1 Like

Oh =0, thank you for your help, I’ll correct!

I am getting Assertion error in course 3 week 1 excercise 1 of practice lab. I changed the code according to the hint given. But it is showing the same error.

Hi Vani,

Could you please share the screenshot of your code?! Since you got the same error as me, I think I can help =).

I think we can share our code to the mentors only. Then, what changes you have made to your code?

What I needed to do was to put the line of code that calculates the index of minimum value in distance inside the loop.

I have written that line of code inside the outer for loop, outside inner for loop. Am I right?

It needs to be inside the inner for loop as well.

I made that change. But… No change.

I sent you a private message, let me know if it helped(!).

I have changed the variable… But no use… Same error…

Hi @VANI_M ,

Looking at the screenshot you posted here, the problem is the line of code where distance = []. This variable needs to be cleared for each example as you go through the ‘for’ loop, because each example is measured for the shortest distance to each of the centroids. If you move that line to just below the first ‘for’ statement, it should work.

Thank you… I got the answer.