Last active
July 30, 2021 02:40
-
-
Save caffeine-potent/e885a11333be566f33f9a5d2a0c1f2e8 to your computer and use it in GitHub Desktop.
Geometric Median in one line of native python.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scipy.spatial.distance import euclidean | |
points = [ | |
[1,3], | |
[2,4], | |
[3,3], | |
[4,5], | |
[3,7], | |
[5,1], | |
[5,3], | |
[6,2] | |
] | |
distance = euclidean | |
geometric_mediod = min(map(lambda p1:(p1,sum(map(lambda p2:distance(p1,p2),points))),points), key = lambda x:x[1])[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey! that "geometric median in one line of native python" made me think it was the geometric mean but its actually the medoid isn't it?