Skip to content
← Back to Community
testt
Profile icon
lij12

def findClosestCentres(X,mu):

finds the centre in mu closest to each point in X

(k, n) = mu.shape # k is number of centres
(m, n) = X.shape # m is number of data points
C= [[]for i in range(k)]
matrix=[[]for i in range(k)]
for i in range(m):
matrix = list(map(lambda muj: np.sum((X[i] - muj) ** 2), mu))
#for j in range(k):
# matrix[j]=np.sum((X[i]-mu[j])**2)
mm=matrix.index(min(matrix))
C[mm].append(i)

insert your code here

return C

Voters
Profile icon
mustafamustaf21
Profile icon
lij12