code: def _sanitize_labels(mat_shape, labels):
      """Help for plot_matrix."""
      # we need a list so an empty one will be cast to False
      if isinstance(labels, np.ndarray):
          labels = labels.tolist()
      if labels and len(labels) != mat_shape[0]:
          raise ValueError(
              "Length of labels unequal to length of matrix."
          )
      return labels
  
imports: import warnings
  import matplotlib.patches
  import matplotlib.pyplot
  import numpy
  import pandas
  from mpl_toolkits.axes_grid1 import make_axes_locatable
  from scipy.cluster.hierarchy import leaves_list, linkage, optimal_leaf_ordering
  from nilearn.glm.first_level.experimental_paradigm import check_events
  from .._utils import fill_doc
label_desc: Use image node_id 4 for calling a global function with example usage: _sanitize_labels(mat_shape, labels) and returns: labels