def cosine_similarity(v, w): return dotProduct(v, w) / math.sqrt(dotProduct(v, v) * dotProduct(w, w))
def transformVector(v, components): return [dotProduct(v, w) for w in components]
def matrix_product_entry(A, B, i, j): return dotProduct(getRow(A, i), getCol(B, j))
def __directionalVarianceGradiant(xi, w): projectionLength = dotProduct(xi, direction(w)) return [2 * projectionLength * xij for xij in xi]
def project(v, w): projectionLength = dotProduct(v, w) return scalarMultiply(projectionLength, w)
def __directionalVarianceI(xi, w): return dotProduct(xi, direction(w)) ** 2
def covariance(x, y): n = len(x) return dotProduct(de_mean(x), de_mean(y)) / (n - 1)
def __directionalVarianceI(xi, w): return dotProduct(xi, direction(w))**2