@@ -172,7 +172,7 @@ def _setdata(self, x, y, res):
172
172
self .lastcluster_idx = None
173
173
return
174
174
175
- def next (self ):
175
+ def cluster_next_point (self ):
176
176
"""Cluster point with largest y-coordinate left, returning self.
177
177
178
178
next() always adds at least one additional point to the existing
@@ -217,14 +217,13 @@ def next(self):
217
217
else :
218
218
# insert right of nearest cluster
219
219
self .lastcluster_idx = nearest_cluster [0 ] + 1
220
- self .clusters = np .insert (self .clusters , self .lastcluster_idx , [test_idx , test_idx ], 0 )
220
+ self .clusters = np .insert (self .clusters , int ( self .lastcluster_idx ) , [test_idx , test_idx ], 0 )
221
221
return self
222
222
223
223
def makeclusters (self ):
224
224
"""Cluster all remaining data."""
225
- for i in self :
226
- pass
227
- return
225
+ while self .current_idx > 0 :
226
+ self .cluster_next_point ()
228
227
229
228
def find_nearest_cluster2 (self , x ):
230
229
"""Return [cluster index, distance] for cluster nearest to x.
@@ -286,8 +285,8 @@ def find_nearest_cluster(self, idx):
286
285
# Calculate which of the two nearest clusters is closer
287
286
distances = np .array (
288
287
[
289
- self .x [idx ] - self .x [self .clusters [near_idx - 1 , 1 ]],
290
- self .x [idx ] - self .x [self .clusters [near_idx , 0 ]],
288
+ self .x [idx ] - self .x [self .clusters [int ( near_idx ) - 1 , 1 ]],
289
+ self .x [idx ] - self .x [self .clusters [int ( near_idx ) , 0 ]],
291
290
]
292
291
)
293
292
if distances [0 ] < np .abs (distances [1 ]):
0 commit comments