Data Science latest module excerise Pandas Pandas Pandas
I'm trying to solve the latest code project Pandas Pandas Pandas. I'm able to pass question 1, 2, 4, and 5, but failed at 3 every time, and the playground doesn't give any feedback. I tried my code on PC, simulating all data points belong to the same cluster and leaving 2nd centroid empty, it doesn't give any error. Can anyone give me some pointer by telling me what's wrong without giving any code? I saw other person shared their code and decided not to read it. I want to do it myself. Thanks. n = int(input()) # this line is not provided in the exercise X = [float(x) for i in range(n) for x in input().split()] # reshape to 2d array for easier euclidean compution import numpy as np X = np.array(X).reshape(-1, 2) # init centroid clusterA = np.array([0,0]) clusterB = np.array([2,2]) # compute euclidean and store the datapoints to the nearest group as a list groupA = [] groupB = [] import numpy as np for i in range(len(X)): ga = np.sqrt(((clusterA - X[i])**2).sum()) gb = np.sqrt(((clusterB - X[i])**2).sum()) if ga <= gb: groupA.append(X[i]) else: groupB.append(X[i]) # reshape to 2d array for easier compution, store result in res groupA = np.array(groupA).reshape(-1,2) groupB = np.array(groupB).reshape(-1,2) res = [] # if the group is empty, append 2 None, otherwise append the mean of x and y (cluster centroid) if len(groupA)==0: res.append(None) res.append(None) else: res.append(groupA[:,0].mean().round(2)) res.append(groupA[:,1].mean().round(2)) if len(groupB)==0: res.append(None) res.append(None) else: res.append(groupB[:,0].mean().round(2)) res.append(groupB[:,1].mean().round(2)) # reshape res to 2d array and use index to print out the answer res = np.array(res).reshape(-1,2) print(res[0]) print(res[1])