-
-
Save douglaspsteen/2f71a3abed860e07b5970b960406a981 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
# Calculate distance between two points | |
def minkowski_distance(a, b, p=1): | |
# Store the number of dimensions | |
dim = len(a) | |
# Set initial distance to 0 | |
distance = 0 | |
# Calculate minkowski distance using parameter p | |
for d in range(dim): | |
distance += abs(a[d] - b[d])**p | |
distance = distance**(1/p) | |
return distance | |
# Test the function | |
minkowski_distance(a=X.iloc[0], b=X.iloc[1], p=1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment