Move the Centers
Each row of points and of centers is a point. Do one round of clustering:
1. Give every point to its nearest center (straight-line distance; on a tie, the center with the lower row).
2. Return the centers after each one moves to the mean of its points. A center with no points stays where it is. No loops: for and while are not allowed.
Example 1
points [[0,0],[2,0],[10,10]]
centers [[0,0],[9,9]]
returns [[1.0,0.0],[10.0,10.0]]
The first two points are nearest to center 0, which moves to their mean (1, 0). The third point pulls center 1 to (10, 10).
Constraints
1 <= len(points) <= 60,1 <= len(centers) <= 6- Points and centers have the same number of columns, 1 to 3
- Coordinates are whole numbers from -20 to 20
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More NumPy problems
- Next GenerationHard
- Runs of Equal ValuesHard
- Two Closest PointsHard
- Vote of the NearestHard
- Above Average CountBeginner
- Average TemperatureBeginner
- Black and WhiteBeginner
- Celsius to FahrenheitBeginner