"""
Cosine angle between two vectors for determining similarity of vectors

Parameters:
    w1: vector of word 1
    w2: vector of word 2

Returns:
    Cosine distance between two vectors. Ranges from -1 (vectors pointing in opposite direction)
    to 1 (vectors pointing in the same direction)

cosine(w1, w2) = (w1·w2) / (|w1| |w2|)

eg. word-word matrix
             |  pie | data | computer
-------------------------------------
cherry       | 442  |  8   |  2
-------------------------------------
digital      |  5   | 1683 | 1670
-------------------------------------
information  |  5   | 3982 | 3325

Represented in the data structures:

matrix = np.array([
    [442, 8, 2],
    [5, 1683, 1670],
    [5, 3982, 3325]
])

cherry = matrix[0]
information = matrix[2]

cosine_distance(cherry, data)
# 0.01775392946668344
"""
import numpy as np
from numpy.linalg import norm

def cosine_distance(w1, w2):
   dist = np.dot(w1, w2) / (norm(w1) * norm(w2))
   return dist
