Created
November 3, 2015 12:31
-
-
Save Killavus/6d6f7393080734ade070 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# M1 (N x A) -> M2 (N x B) -> DM (A x B) | |
def ComputeDistanceMatrix(M1, M2): | |
# For each r-th row: Sum(k = 1, N) M1(r, k) ** 2 | |
SM1 = np.sum(M1 ** 2) | |
# For each r-th row: Sum(k = 1, N) M2(r, k) ** 2 | |
SM2 = np.sum(M2 ** 2) | |
# The last term: 2 * (M1 x M2^T) | |
M1M2_2 = 2 * np.dot(M1, M2.T) | |
return np.sqrt(M1M2_2 + SM1 + SM2) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment