Skip to content

Instantly share code, notes, and snippets.

@weilinear
Created November 20, 2012 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weilinear/4117966 to your computer and use it in GitHub Desktop.
Save weilinear/4117966 to your computer and use it in GitHub Desktop.
Manhattan Distances for Sparse Matrix
from scipy.sparse import csr_matrix
from sklearn.metrics.pairwise import manhattan_distances
A = csr_matrix(np.array([[1,2,3],[8,9,0]],dtype=np.float))
B = csr_matrix(np.array([[1,2,4],[3,4,5]],dtype=np.float))
C = manhattan_distances(A, B)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment