Write and suppose the cluster is nonempty. Expanding the Euclidean norm through its inner product givesSum over . The final term does not depend on , so its sum is , which proves the requested identity. This expansion is the starting point for the centroid sum-of-squares identity.
Combining the first two parts gives the centroid sum-of-squares identityThe added term is nonnegative and, since , vanishes exactly at . Thus the unique minimizing centroid in this step of K-means clustering isAn empty cluster needs a separate algorithmic convention because its sample mean is undefined and its objective is identically zero.