code: public DoubleVector[] getCentroids() {
          if (matrix == null)
              throw new IllegalArgumentException(
                      "The data matrix was not passed to Assignments.");
  
          // Initialzie the centroid vectors and the cluster sizes.
          DoubleVector[] centroids = new DoubleVector[numClusters];
          counts = new int[numClusters];
          for (int c = 0; c < numClusters; ++c)
              centroids[c] = new DenseVector(matrix.columns());
  
          // For each initial assignment, add the vector to it's centroid and
          // increase the size of the cluster.
          int row = 0;
          for (Assignment assignment : assignments) {
              if (assignment.length() != 0) {
                  // NOTE: why is this only using the first cluster?  Is this a
                  // bug? -david
                  int clus = assignment.assignments()[0];
                  // Skip items whose cluster assignment indicates they were not
                  // assigned to any cluster.
                  if (clus < 0)
                      continue;
                  counts[clus]++;
                  DoubleVector centroid = centroids[assignment.assignments()[0]];
                  VectorMath.add(centroid, matrix.getRowVector(row));
              }
              row++;
          }
  
          // Scale any non empty clusters by their size.
          for (int c = 0; c < numClusters; ++c)
              if (counts[c] != 0)
                  centroids[c] = new ScaledDoubleVector(
                          centroids[c],1d/counts[c]);
  
          return centroids;
      }
docs: Returns an array of dense centroid vectors of each discovered cluster
  which are scaled according the the number of data points asisgned to that
  cluster.  Note that this method assumes that the original {@link Matrix}
  holding the data points contains rows of feature vectors.