-
-
Save SemantiveCode/986c31a0e2e517dff209f1872731140d 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 numpy as np | |
def dummy_mat(mat_v, mat_u): | |
return [sum((v_i - u_i)**2 for v_i, u_i in zip(v, u))**0.5 for v, u in zip(mat_v, mat_u)] | |
def bare_numpy_mat(mat_v, mat_u): | |
return np.sqrt(np.sum((mat_v - mat_u) ** 2, axis=1)) | |
def l2_norm_mat(mat_v, mat_u): | |
return np.linalg.norm(mat_v - mat_u, axis=1) | |
def scipy_distance_mat(mat_v, mat_u): | |
# Unfortunately, the scipy_distance only works on 1D-arrays, so we are not able to vectorize it again. | |
return list(map(distance.euclidean, mat_v, mat_u)) | |
def einsum_mat(mat_v, mat_u): | |
mat_z = mat_v - mat_u | |
return np.sqrt(np.einsum('ij,ij->i', mat_z, mat_z)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment