Python Forum

Full Version: Numpy library working out cosine.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
import numpy as np

a = np.array([1, 2])
b = np.array([2, 1])

dot = 0

cosangle = a.dot(b) / (np.linalg.norm(a) * np.linalg.norm(b))
print(cosangle)
So I'm following a tutorial and the guy doesn't explain allot in terms of why this actually gives
the value of the cosine. Please Help.
This is the first formula in the Geometric Definition section in the wikipedia page about the dot product.