/top/
/new/
/best/
/ask/
/show/
/job/
^
slacker news
login
about
←back to thread
How to Implement a Cosine Similarity Function in TypeScript
(alexop.dev)
86 points
alexop
| 1 comments |
09 Mar 25 09:20 UTC
|
HN request time: 0s
|
source
Show context
raverbashing
◴[
11 Mar 25 06:29 UTC
]
No.
43329726
[source]
▶
>>43307541 (OP)
#
Meanwhile in Python this is just
(a @ b.T)/(np.linalg.norm(a)*np.linalg.norm(b))
replies(1):
>>43330264
#
forgotpwd16
◴[
11 Mar 25 08:08 UTC
]
No.
43330264
[source]
▶
>>43329726
#
Because you use numpy. Could as well import cosine_similarity from sklearn.
replies(1):
>>43331468
#
1.
Etherlord87
◴[
11 Mar 25 11:41 UTC
]
No.
43331468
[source]
▶
>>43330264
#
you could also normalize (divide all components by magnitude) both vectors and simply take the dot product?
ID:
GO
↑