Last active
October 14, 2019 00:16
-
-
Save mmmayo13/1fdd78a33ba9d264f241e65360689e76 to your computer and use it in GitHub Desktop.
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
import scipy.spatial.distance as dist | |
import numpy as np | |
# Prepare 2 vectors (data points) of 10 dimensions | |
A = np.random.uniform(0, 10, 10) | |
B = np.random.uniform(0, 10, 10) | |
print '\n2 10-dimensional vectors' | |
print '------------------------' | |
print A | |
print B | |
# Perform distance measurements | |
print '\nDistance measurements with 10-dimensional vectors' | |
print '-------------------------------------------------' | |
print '\nEuclidean distance is', dist.euclidean(A, B) | |
print 'Manhattan distance is', dist.cityblock(A, B) | |
print 'Chebyshev distance is', dist.chebyshev(A, B) | |
print 'Canberra distance is', dist.canberra(A, B) | |
print 'Cosine distance is', dist.cosine(A, B) | |
# Prepare 2 vectors of 100 dimensions | |
AA = np.random.uniform(0, 10, 100) | |
BB = np.random.uniform(0, 10, 100) | |
# Perform distance measurements | |
print '\nDistance measurements with 100-dimensional vectors' | |
print '--------------------------------------------------' | |
print '\nEuclidean distance is', dist.euclidean(AA, BB) | |
print 'Manhattan distance is', dist.cityblock(AA, BB) | |
print 'Chebyshev distance is', dist.chebyshev(AA, BB) | |
print 'Canberra distance is', dist.canberra(AA, BB) | |
print 'Cosine distance is', dist.cosine(AA, BB) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment