Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
CoNekT/utils/vector.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
22 lines (16 sloc)
435 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import sqrt | |
def dot_prod(a, b): | |
""" | |
Calculates the dot product of two lists with values | |
:param a: first list | |
:param b: second list | |
:return: dot product (a . b) | |
""" | |
return sum([i*j for (i, j) in zip(a, b)]) | |
def norm(a): | |
""" | |
Calculates the Frobenius norm for a list of values | |
:param a: list of values | |
:return: the Frobenius norm | |
""" | |
return sqrt(sum([i**2 for i in a])) |