SimpleMatrix averageVector = new SimpleMatrix(1,noFeatures);
for (Integer sample : (ArrayList<Integer>) centroids.get(centroid).trainingExamples) {
averageVector = averageVector.plus(datasetMatrix.extractVector(true, sample));
}
averageVector = averageVector.divide(centroids.get(centroid).trainingExamples.size());
if (isClassification) {
for( int i = 0; i < averageVector.getNumElements(); i++ )
averageVector.set(i,Math.round(averageVector.get(i)));
}