code: def _compute_inertia(distances, assignments, squared=True):
      """Derive inertia (average of squared distances) from pre-computed
      distances and assignments.
  
      Examples
      --------
      >>> dists = numpy.array([[1., 2., 0.5], [0., 3., 1.]])
      >>> assign = numpy.array([2, 0])
      >>> _compute_inertia(dists, assign)
      0.125
      """
      n_ts = distances.shape[0]
      if squared:
          return (
              numpy.sum(distances[numpy.arange(n_ts), assignments] ** 2)
              / n_ts
          )
      else:
          return (
              numpy.sum(distances[numpy.arange(n_ts), assignments])
              / n_ts
          )
  
file_path: tslearn/tslearn/clustering/utils.py
imports: from sklearn.metrics.cluster import silhouette_score
  from scipy.spatial.distance import cdist
  import numpy
  from tslearn.metrics import cdist_dtw, cdist_soft_dtw_normalized
  from tslearn.preprocessing import TimeSeriesResampler
  from tslearn.utils import to_time_series_dataset, to_time_series
label_desc: Use image node_id 3 for calling a global function with example usage: _compute_inertia(distances, assignments, squared) and returns: unknown, unknown