1
0
Fork 0

Compute centroid means (vectorized)

master
neingeist 10 years ago
parent 39b09f144a
commit 6c51a29ca2

@ -27,17 +27,9 @@ centroids = zeros(K, n);
%
for k = 1:K
count = 0;
% XXX vectorize
for i = 1:m
if idx(i) == k
centroids(k, :) += X(i, :);
count += 1;
end
end
if count > 0
centroids(k, :) /= count;
X_in_k = X(idx == k, :);
if size(X_in_k, 1) > 0
centroids(k, :) = sum(X_in_k)/size(X_in_k, 1);
end
end