Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sklearn.metrics.pairwise import cosine_similarity
- from scipy import sparse
- a = np.random.random((3, 10))
- b = np.random.random((3, 10))
- # Create sparse matrices, which compute faster and give more understandable output
- a_sparse, b_sparse = sparse.csr_matrix(a), sparse.csr_matrix(b)
- sim_sparse = cosine_similarity(a_sparse, b_sparse, dense_output=False)
- print(sim_sparse)
- (0, 2) 0.7938732813430508
- (0, 1) 0.7575978172453429
- (0, 0) 0.7897664361147338
- (1, 2) 0.740418315571796
- (1, 1) 0.833981672896221
- (1, 0) 0.7184526671218405
- (2, 2) 0.8746293481677073
- (2, 1) 0.6456666045233884
- (2, 0) 0.7925289217609924
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement