Quantcast
Channel: User David Z - Stack Overflow
Viewing all articles
Browse latest Browse all 49

Answer by David Z for How to calculate the cosine similarity betwen list to lists?

$
0
0

You need to change a couple things: first, when using dot(), the last dimension of the first array needs to match the second-to-last dimension of the second array, so in your case what you probably want is dot(a, b.T). Then, in order to compute the norm of each constituent array within b instead of computing the norm of b as a matrix, you need norm(b, axis=1). Putting those together, you probably should use dot(a, b.T) / (norm(a) * norm(b, axis=1)).


Viewing all articles
Browse latest Browse all 49

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>