Bird
0
0

What will be printed by this Python code snippet?

medium📝 Predict Output Q4 of 15
NLP - Text Similarity and Search
What will be printed by this Python code snippet?
from sklearn.metrics.pairwise import cosine_similarity
import numpy as np
v1 = np.array([[1, 0, 0]])
v2 = np.array([[0, 1, 0]])
similarity = cosine_similarity(v1, v2)
print(similarity[0][0])
A0.5
B1.0
C0.0
DError due to shape mismatch
Step-by-Step Solution
Solution:
  1. Step 1: Understand vectors

    v1 and v2 are orthogonal unit vectors along different axes.
  2. Step 2: Compute cosine similarity

    Cosine similarity between orthogonal vectors is 0.
  3. Final Answer:

    0.0 -> Option C
  4. Quick Check:

    Orthogonal vectors have zero cosine similarity. [OK]
Quick Trick: Orthogonal vectors yield zero cosine similarity [OK]
Common Mistakes:
MISTAKES
  • Assuming similarity is 1 for any vectors
  • Confusing dot product with cosine similarity
  • Ignoring vector shapes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NLP Quizzes