intro-to-python/sample_package/utils.py
Alexander Hess ec3097e220 Add the sample_package folder to the project
The sample_package folder serves as an example in notebook 02 as to what
a Python package looks like. Its contents actually belong to the chapter
on object-orientation.
2019-09-22 20:26:58 +02:00

14 lines
362 B
Python

"""This module provides utility functions."""
def norm(vector_or_matrix):
"""Calculate the Frobenius or Euclidean norm of a matrix or vector.
Args:
vector_or_matrix (Vector/Matrix): the entries whose squares
are to be summed up
Returns:
norm (float)
"""
return math.sqrt(sum(x ** 2 for x in vector_or_matrix))