#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import numpy as np
import sklearn
from sklearn import cluster
from sklearn.cluster import AffinityPropagation

matrice = sys.argv[1]

X = np.loadtxt(matrice) # lecture de la matrice à partir d'un fichier

if len(X.shape)==0:
    print 'Number of clusters: 1'
    print 'Cluster centers:'
    print '0'
    print 'Cluster groups:'
    print '0'

else:
    af = AffinityPropagation(affinity='precomputed').fit(X)

    cluster_centers_indices = af.cluster_centers_indices_
    labels = af.labels_
    n_clusters_ = len(cluster_centers_indices)


    print('Number of clusters: %d' % n_clusters_)
    print 'Cluster centers:' 
    print cluster_centers_indices

    def ClusterIndicesNumpy(clustNum, labels_array): #numpy 
            return np.where(labels_array == clustNum)[0]

    print 'Cluster groups:'

    for i in range(0,n_clusters_) :
        a = ClusterIndicesNumpy(i, labels)
        print a


