Question regarding C3_W1_KMeans_Assignment:

Hi all,
I implemented the find_closest_centroids function this way:

{moderator edit: code removed}

I know it’s not the expected solution from the hints, but I wanted to implement it as I know.
The result I received was good, meaning I received the output: First three elements in idx are: [0 2 1]

But then unit test printed:
AssertionError Traceback (most recent call last)
in
11 from public_tests import *
12
—> 13 find_closest_centroids_test(find_closest_centroids)

~/work/public_tests.py in find_closest_centroids_test(target)
39 assert type(idx) == np.ndarray, “Wrong type”
40 assert idx.shape == (len(X),), f"Wrong shape. Expected: {(len(X),)} got: {idx.shape}"
—> 41 assert np.allclose(idx, [0, 0, 0, 1, 1, 1]), “Wrong values”
42
43 # With 3 centroids

AssertionError: Wrong values

What should I do? Was my solution good or bad?
Thanks,
Asaf.

Hi @Asaf.H, Welcome back to the community!!!

There are a couple of corrections that need to be made to the find_closest_centroids function that you provided. Firstly, both loops should start from index 0 instead of 1, so it should be range(M) and range(K) .

Here, you forget to assign current distance to the variable temp . :grin:

Best,
Mujassim

@Asaf.H: Please do not post your code on the forum. That’s not allowed by the community guidelines.

I have removed the code from your post.

If a mentor needs to see your code, they’ll ask you to send it to them privately.

My apologies Tom, It was done absentmindedly.
If I will need to get feedback on my code in the future, how is it available? Is there a way to contact the mentors personally?

You should not contact a mentor personally unless they invite you to.

In general, we can diagnose most errors in your code by just looking at a screen capture that shows any error messages and the assert stack.

If that’s not sufficient to diagnose the problem, then a mentor may ask you to send your notebook to them.