code: def _reorder_by_cluster(association_matrix):
      """Reorder an association matrix by cluster distances.
  
      Args:
          association_matrix: A matrix of associations (similarity)
  
      Returns:
          A Pandas data frame
      """
      distance = 1 - association_matrix
  
      # Determine padding dimensions, if non-square
      max_dim = max(distance.shape[0], distance.shape[1])
      pad_distance = np.pad(
          distance,
          (
              (0, min(1, max_dim - distance.shape[0])),
              (0, min(1, max_dim - distance.shape[1])),
          ),
          mode="constant",
          constant_values=0,
      )
  
      if distance.shape[0] == distance.shape[1]:
          y = np.array(pad_distance)[
              np.triu_indices_from(pad_distance, 1)
          ]
      else:
          # Non-square matrix
          y = np.array(pad_distance)[
              np.tril_indices_from(pad_distance, 1)
          ]
  
      # Use hierarchical clustering to get order
      link = hierarchy.linkage(y)
      dendrogram = hierarchy.dendrogram(
          link, get_leaves=True, no_plot=True
      )
      new_order = [x for x in dendrogram["leaves"] if x < max_dim]
  
      reorder_corr = pd.DataFrame(
          [
              row[new_order]
              for row in association_matrix.values[new_order]
          ]
      )
  
      # Assign column and row labels
      reorder_corr.columns = [
          association_matrix.columns.values[i] for i in new_order
      ]
      reorder_corr.set_index(
          np.array(
              [association_matrix.columns.values[i] for i in new_order]
          ),
          inplace=True,
      )
  
      return reorder_corr
  
imports: import warnings
  import pandas
  import numpy
  from scipy.cluster import hierarchy
  from sklearn.metrics import matthews_corrcoef
  from scipy.stats import chi2_contingency
  import seaborn
  import matplotlib.pyplot
  import plotly.graph_objs
  import plotly.offline
  from data_describe.config._config import get_option
  from data_describe.misc.colors import get_p_RdBl_cmap, mpl_to_plotly_cmap
  from data_describe._widget import BaseWidget
  from data_describe.compat import _is_dataframe, _in_notebook, _requires
  from data_describe.backends import _get_viz_backend, _get_compute_backend
label_desc: Use image node_id 7 for calling a global function with example usage: _reorder_by_cluster(association_matrix) and returns: reorder_corr