   function [ctrs,idx] = myKmeans(X,ND,max_its)
%% function [ctrs,idx] = myKmeans(X,ND,max_its)
  if (nargin < 3)
    max_its = 20;
  end
  ctrs = zeros(ND,size(X,2)); 
  idx = randperm(size(X,1));
  ctrs = X(idx(1:ND), :);

for i=1:max_its
  idx  = getClosestCtrs(X, ctrs);
  ctrs = getCentroids(X, idx, ND);
end

idx  = getClosestCtrs(X, ctrs);