promptdojo_

Clustering without labels — step 5 of 7

This k-means crashes with ZeroDivisionError: the third starting center (50.0) is so far from every point that its cluster is EMPTY, and the update divides by len([]) = 0. Fix the update to keep a center where it was when no points were assigned to it.

The break is on line 9 — but read the whole snippet first.

full-screen editor opens — close anytime to keep reading.