Commit 417e1bef96f8f60201e0fd84b645d8aac00579d6
1 parent
1b1ed7e2
small improvements
Showing
3 changed files
with
5 additions
and
7 deletions
Show diff stats
main.py
structure.py
... | ... | @@ -239,7 +239,7 @@ def KNeighbors(fingerprints, sample): |
239 | 239 | :param sample: Mobile terminal sample |
240 | 240 | :return: the 4 nearest cells |
241 | 241 | ''' |
242 | - distances, neighbours = [], [] | |
242 | + distances = [] | |
243 | 243 | for row in fingerprints: |
244 | 244 | for currentItem in row: |
245 | 245 | dist = abs(currentItem.v.n1 - sample.n1) \ |
... | ... | @@ -248,10 +248,8 @@ def KNeighbors(fingerprints, sample): |
248 | 248 | + abs(currentItem.v.n4 - sample.n4) |
249 | 249 | distances.append((dist, currentItem)) |
250 | 250 | distances = sorted(distances, key=ig(0)) |
251 | - for k in range (0,4): | |
252 | - neighbours.append(distances[k][1]) | |
253 | - sample.distances.append(distances[k][0]) | |
254 | - return neighbours | |
251 | + sample.distances = [x[0] for x in distances][:4] | |
252 | + return [x[1] for x in distances][:4] | |
255 | 253 | |
256 | 254 | |
257 | 255 | ... | ... |
test_structure.py