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