When creating a post, please add:
- Week # must be added in the tags option of the post.
- Link to the classroom item you are referring to:
- Description (include relevant info but please do not post solution code or your entire notebook):
Select an initial set of centroids (3 Centroids)
initial_centroids = np.array([[3,3], [6,2], [8,5]])
Find closest centroids using initial_centroids
idx = find_closest_centroids(X, initial_centroids)
Print closest centroids for the first three elements
print(“First three elements in idx are:”, idx[:3])
UNIT TEST
from public_tests import *
find_closest_centroids_test(find_closest_centroids)
IndexError Traceback (most recent call last)
in
6
7 # Print closest centroids for the first three elements
----> 8 print(“First three elements in idx are:”, idx[:3])
9
10 # UNIT TEST
IndexError: invalid index to scalar variable.
Could someone help me with this. After writing my code for the ‘find_closest_centroids’ function, and running the subsequent given codes, I got this error message which seems right to me because I believe there are 3 elements in the ‘initial_centroids’ variable. How do I proceed since I can’t change that part of the code? What am I missing?