Canonicalization

For reviewing this code
Use axis argument for dist_matrix to calculate all means at once.