We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3085c5e commit e6cc1caCopy full SHA for e6cc1ca
1 file changed
Mapping/kmean_clustering/kmean_clustering.py
@@ -11,6 +11,29 @@
11
import random
12
13
14
+class Cluster:
15
+
16
+ def __init__(self):
17
+ self.x = []
18
+ self.y = []
19
+ self.cx = None
20
+ self.cy = None
21
22
23
+def kmean_clustering(rx, ry, nc):
24
25
+ minx, maxx = min(rx), max(rx)
26
+ miny, maxy = min(ry), max(ry)
27
28
+ clusters = [Cluster() for i in range(nc)]
29
30
+ for c in clusters:
31
+ c.cx = random.uniform(minx, maxx)
32
+ c.cy = random.uniform(miny, maxy)
33
34
+ return clusters
35
36
37
def calc_raw_data():
38
39
rx, ry = [], []
@@ -33,7 +56,14 @@ def main():
56
57
rx, ry = calc_raw_data()
58
- plt.plot(rx, ry, "x")
59
+ ncluster = 2
60
+ clusters = kmean_clustering(rx, ry, ncluster)
61
62
63
+ print(c.cx, c.cy)
64
+ plt.plot(c.cx, c.cy, "x")
65
66
+ plt.plot(rx, ry, ".")
67
plt.show()
68
69
0 commit comments