From a874fc5af210e969c3191e74a4bf0b4301894df2 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Wed, 5 Oct 2016 11:55:36 -0400 Subject: [PATCH] Add a norm function to the matrices module. --- matrices.py | 7 +++++++ 1 file changed, 7 insertions(+) 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])) -- 2.43.2