Skip to content

Commit 714b39f

Browse files
committed
update_dist now works as described.
1 parent 9e275e6 commit 714b39f

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

docs/13-kmeans-project.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,22 @@ We need to repeatetly get the eucledian distances of one centroid against all ge
203203
Implement a ``dist_to_centroid (centroid, mat )`` function.
204204

205205

206-
??? example "Again only peak after you finished yours"
206+
??? example "Peak only after you finished yours"
207207

208208
```python
209+
## I am sure yours performs way better!
210+
def dist( vec_a, vec_b ):
211+
"""
212+
Calculates the distance between two numpy arrays
213+
"""
214+
if len(vec_a) != len(vec_b):
215+
raise ValueError("Vectors must have the same length.")
216+
217+
sum = 0.0
218+
for (a,b) in vec_a.zip(vec_b):
219+
sum += (a -b) ** 2
220+
return (sum ** 0.5)
221+
209222
def dist_to_centroid (centroid, mat ):
210223
"""
211224
Calculates eucledian distance between one centroid and a matrix of genes

0 commit comments

Comments
 (0)