code: def _inertia_from_labels(X, centers, labels):
      
      n_examples, n_features = X.shape
      inertia = np.zeros((n_examples,))
      for ee in range(n_examples):
          inertia[ee] = 1 - X[ee, :].dot(centers[int(labels[ee]), :].T)
  
      return np.sum(inertia)
docs: Compute inertia with cosine distance using known labels.