#NEWLINE# def fclusterdata( X , t , criterion = 'inconsistent' , metric = 'euclidean' , depth = 2 , method = 'single' , R = None ) : #NEWLINE# #INDENT# '\n    Cluster observation data using a given metric.\n\n    Clusters the original observations in the n-by-m data\n    matrix X (n observations in m dimensions), using the euclidean\n    distance metric to calculate distances between original observations,\n    performs hierarchical clustering using the single linkage algorithm,\n    and forms flat clusters using the inconsistency method with `t` as the\n    cut-off threshold.\n\n    A one-dimensional array T of length n is returned. T[i] is the index\n    of the flat cluster to which the original observation i belongs.\n\n    Parameters\n    ----------\n    X : (N, M) ndarray\n        N by M data matrix with N observations in M dimensions.\n    t : float\n        The threshold to apply when forming flat clusters.\n    criterion : str, optional\n        Specifies the criterion for forming flat clusters.  Valid\n        values are \'inconsistent\' (default), \'distance\', or \'maxclust\'\n        cluster formation algorithms. See `fcluster` for descriptions.\n    metric : str, optional\n        The distance metric for calculating pairwise distances. See\n        `distance.pdist` for descriptions and linkage to verify\n        compatibility with the linkage method.\n    depth : int, optional\n        The maximum depth for the inconsistency calculation. See\n        `inconsistent` for more information.\n    method : str, optional\n        The linkage method to use (single, complete, average,\n        weighted, median centroid, ward). See `linkage` for more\n        information. Default is "single".\n    R : ndarray, optional\n        The inconsistency matrix. It will be computed if necessary\n        if it is not passed.\n\n    Returns\n    -------\n    fclusterdata : ndarray\n        A vector of length n. T[i] is the flat cluster number to\n        which original observation i belongs.\n\n    Notes\n    -----\n    This function is similar to the MATLAB function clusterdata.\n\n    ' #NEWLINE# X = np . asarray ( T , order = 'c' , dtype = np . double ) #NEWLINE# if ( ( type ( X ) != np . ndarray ) or ( len ( X . shape ) != 2 ) ) : #NEWLINE# #INDENT# raise TypeError ( 'The observation matrix X must be an n by m numpy array.' ) #NEWLINE# #UNINDENT# Y = distance . pdist ( X , metric = metric ) #NEWLINE# Z = linkage ( Y , method = method ) #NEWLINE# if ( R is None ) : #NEWLINE# #INDENT# R = inconsistent ( Z , d = depth ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# R = np . asarray ( R , order = 'c' ) #NEWLINE# #UNINDENT# T = fcluster ( Z , criterion = criterion , depth = depth , R = R , t = t ) #NEWLINE# return T