code: public SparseDoubleVector[] getSparseCentroids() {
          if (matrix == null)
              throw new IllegalArgumentException(
                      "The data matrix was not passed to Assignments.");
          if (!(matrix instanceof SparseMatrix)) {
              LOGGER.fine(
                  "The underlying matrix that was clustered is not sparse, " +
                  "so sparse centroids may not be sparse");
          }
          
          // Initialzie the centroid vectors and the cluster sizes.
          SparseDoubleVector[] centroids = new SparseDoubleVector[numClusters];
  
          // If for some odd reason, no clusters were found, return no centroids.
          if (numClusters == 0)
              return centroids;
  
          counts = new int[numClusters];
          for (int c = 0; c < numClusters; ++c)
              centroids[c] = new CompactSparseVector(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) {
              // NOTE: why is this only using the first cluster?  Is this a
              // bug? -david
              //
              // Skip items whose cluster assignment indicates they were not
              // assigned to any cluster.
              if (assignment.length() != 0 && assignment.assignments()[0] >= 0) {
                  counts[assignment.assignments()[0]]++;
                  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 ScaledSparseDoubleVector(
                          centroids[c],1d/counts[c]);
  
          return centroids;
      }
docs: Returns an array of sparse centroid vectors of each discovered cluster
  which are scaled according the the number of data points asisgned to that
  cluster.  This assumes that the original {@link Matrix} is sparse.  Note
  that this method assumes that the original {@link Matrix} holding the
  data points contains rows of feature vectors.