code: def hclust_linearize(U):
      
  
      from scipy.cluster import hierarchy
      Z = hierarchy.ward(U)
      return hierarchy.leaves_list(hierarchy.optimal_leaf_ordering(Z, U))
docs: Sorts the rows of a matrix by hierarchical clustering.
  
      Parameters:
          U (ndarray) : matrix of data
  
      Returns:
          prm (ndarray) : permutation of the rows