def reorder_mat(y, clusters, labels=False, reverse=True):
    """Reorder the  matrix according the clusters membership
        @Debug: square matrix
    """
    assert(y.shape[0] == y.shape[1] == len(clusters))
    if reverse is True:
        hist, label = clusters_hist(clusters)
        sorted_clusters = np.empty_like(clusters)
        for i, k in enumerate(label):
            if i != k:
                sorted_clusters[clusters == k] = i
    else:
        sorted_clusters = clusters

    N = y.shape[0]
    nodelist = [k[0] for k in sorted(zip(range(N), sorted_clusters),
                                     key=lambda k: k[1])]

    y_r = y[nodelist, :][:, nodelist]
    if labels is True:
        return y_r, nodelist
    else:
        return y_r