title: How to compute cluster assignments from linkage/distance matrices
body: <p>if you have this hierarchical clustering call in scipy in Python:</p>
  
  <pre><code>from scipy.cluster.hierarchy import linkage
  # dist_matrix is long form distance matrix
  linkage_matrix = linkage(squareform(dist_matrix), linkage_method)
  </code></pre>
  
  <p>then what's an efficient way to go from this to cluster assignments for individual points? i.e. a vector of length <code>N</code> where <code>N</code> is number of points, where each entry <code>i</code> is the cluster number of point <code>i</code>, given the number of clusters generated by a given threshold <code>thresh</code> on the resulting clustering?</p>
  
  <p>To clarify: The cluster number would be the cluster that it's in after applying a threshold to the tree. In which case you would get a unique cluster for each leaf node for the cluster that it is in. Unique in the sense that each point belongs to one "most specific cluster" which is defined by the threshold where you cut the dendrogram. </p>
  
  <p>I know that <code>scipy.cluster.hierarchy.fclusterdata</code> gives you this cluster assignment as its return value, but I am starting from a custom made distance matrix and distance metric, so I cannot use <code>fclusterdata</code>. The question boils down to: how can I compute what <code>fclusterdata</code> is computing -- the cluster assignments?</p>