X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=matrices.py;fp=matrices.py;h=60db346a0a966ed6b686d9c368f3e2b18eb6a73d;hb=a874fc5af210e969c3191e74a4bf0b4301894df2;hp=82944ee72ab77ca676054601991afadcd804ae77;hpb=b1d06cfefc83b4db9d5592f7424d4ef67b9806e7;p=dunshire.git 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]))