from cvxopt import matrix, spmatrix 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_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``. """ return matrix([A,b]) def identity(n): """ Return the ``n``-by-``n`` identity matrix. """ return spmatrix(1,range(n),range(n))