export function initCentroids()

in modules/mlvis-common/src/utils/kmeans.js [42:51]


export function initCentroids(X, nClusters) {
  const indices = [];
  while (indices.length < nClusters) {
    const ind = Math.floor(Math.random() * X.shape[0]);
    if (!indices.includes(ind)) {
      indices.push(ind);
    }
  }
  return tf.gather(X, indices);
}