from cvxopt import matrix, spmatrix from math import sqrt def append_col(A,b): """ Append the column ``b`` to the right side of the matrix ``A``. """ return matrix([A.trans(),b.trans()]).trans() def append_row(A,b): """ Append the row ``b`` to the bottom of the matrix ``A``. """ return matrix([A,b]) 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]))