import numpy as np
from sklearn.cluster import SpectralClustering
lena = np.matrix('1 1 0 0;1 1 0 0;0 0 1 0.2;0 0 0.2 1')
n_clusters = 3
SpectralClustering(n_clusters).fit_predict(lena)
sklearn agglomerative clustering input data