medium10 pts · first answer countspythonembeddings
Cosine of a scaled vector
What does this NumPy code print?
import numpy as np a = np.array([1.0, 2.0, 2.0]) b = np.array([2.0, 4.0, 4.0]) sim = a @ b / (np.linalg.norm(a) * np.linalg.norm(b)) print(round(float(sim), 2))
Discussion 0
Join free to post in the discussion.
Related questions
- What text embeddings areAI Engineer (LLM & Generative AI)
- Comparing two embeddingsAI Engineer (LLM & Generative AI)
- Dot product of two vectorsAI Engineer (LLM & Generative AI)
- Parsing a JSON reply in PythonAI Engineer (LLM & Generative AI)
- Cosine similarity by handAI Engineer (LLM & Generative AI)
- Tracing a retry helperAI Engineer (LLM & Generative AI)
- Dot product on unit vectorsAI Engineer (LLM & Generative AI)
- Semantic cache gives wrong answersAI Engineer (LLM & Generative AI)