From: Michael Orlitzky Date: Wed, 5 Oct 2016 15:55:36 +0000 (-0400) Subject: Add a norm function to the matrices module. X-Git-Tag: 0.1.0~217 X-Git-Url: http://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=a874fc5af210e969c3191e74a4bf0b4301894df2;p=dunshire.git Add a norm function to the matrices module. --- diff --git a/matrices.py b/matrices.py index 82944ee..60db346 100644 --- a/matrices.py +++ b/matrices.py @@ -1,4 +1,5 @@ from cvxopt import matrix, spmatrix +from math import sqrt def append_col(A,b): """ @@ -17,3 +18,9 @@ def identity(n): Return the ``n``-by-``n`` identity matrix. """ return spmatrix(1,range(n),range(n)) + +def norm(x): + """ + Return the Euclidean norm of the given vector. + """ + return sqrt(sum([z**2 for z in x]))