Solution (source code)

= Solution

Combining the first two parts gives the <centroid sum-of-squares identity>
$$
J_k(z)=J_k(\bar x_k)+n_k\|z-\bar x_k\|^2.
$$
The added term is nonnegative and, since $n_k>0$, vanishes exactly at $z=\bar x_k$. Thus the unique minimizing <centroid> in this step of <K-means clustering> is
$$
\boxed{z_k=\bar x_k}.
$$
An empty cluster needs a separate algorithmic convention because its <sample mean> is undefined and its objective is identically zero.