C3_W1_KMeans_Assignment # UNQ_C1 # GRADED FUNCTION: find_closest_centroids

Hello Friends, I am getting following error. I am not sure what is creating this error.
First three elements in idx are: [0 0 0]

AssertionError Traceback (most recent call last)
11 from public_tests import *
—> 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”
43 # With 3 centroids

AssertionError: Wrong values

Expected Output:

First three elements in idx are [0 2 1]


Can you send me your code in a direct message so I can help?

1 Like

Hi, I’m also getting the same error. Any help would be appreciated. Cheers John.

Hi John,

The line below needs to be inside the for i loop as it assigns a centroid to each X[i]

{moderator edit: removing assignment code}

I hope it helps.

Hi ! I’m getting the same error when I write my own code. However, there is no error when I use the code given in Hints. Kindly help.


Can you send me your code in a direct message?

Are you also following the instruction to have idx values range from 1 to K?
Actually, the code is expecting it to be in range 0 to K-1.
I guess, it’s an honest mistake from their side.