X-Git-Url: https://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=matrices.py;h=60db346a0a966ed6b686d9c368f3e2b18eb6a73d;hb=a874fc5af210e969c3191e74a4bf0b4301894df2;hp=01ab35274ed2157cac71af13dd84b0fdf3e4dfd4;hpb=91660cdf9b0662f4d7f1d9ecea516dfea010a729;p=dunshire.git diff --git a/matrices.py b/matrices.py index 01ab352..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): """ @@ -6,21 +7,6 @@ def append_col(A,b): """ return matrix([A.trans(),b.trans()]).trans() -def append_cols(cols): - """ - Append a bunch of columns together, left to right. - """ - if len(cols) == 0: - return cols - - result = cols[0] - del(cols[0]) - for column in cols: - result = append_col(result, column) - - return result - - def append_row(A,b): """ Append the row ``b`` to the bottom of the matrix ``A``. @@ -32,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]))