]> gitweb.michael.orlitzky.com - dunshire.git/blob - matrices.py
Initial commit of something that returns an answer.
[dunshire.git] / matrices.py
1 from cvxopt import matrix, spmatrix
2
3 def append_col(A,b):
4 """
5 Append the column ``b`` to the right side of the matrix ``A``.
6 """
7 return matrix([A.trans(),b.trans()]).trans()
8
9 def append_cols(cols):
10 """
11 Append a bunch of columns together, left to right.
12 """
13 if len(cols) == 0:
14 return cols
15
16 result = cols[0]
17 del(cols[0])
18 for column in cols:
19 result = append_col(result, column)
20
21 return result
22
23
24 def append_row(A,b):
25 """
26 Append the row ``b`` to the bottom of the matrix ``A``.
27 """
28 return matrix([A,b])
29
30 def identity(n):
31 """
32 Return the ``n``-by-``n`` identity matrix.
33 """
34 return spmatrix(1,range(n),range(n))