1 | initial version |
How about this:
signs = ['=','=','>=','>=','>=','<=','<=','<=','<=','<=']
# lines: will be the rows of the matrix
lines = []
# column: where to put the next nonzero entry
column = 0
# total number of columns in matrix
size = sum(len(s) for s in signs)
for s in signs:
if s == '=':
new = column * [0] + [1] + (size - column - 1) * [0]
column += 1
elif s == '>=':
new = column * [0] + [-1, 1] + (size - column - 2) * [0]
column += 2
elif s == '<=':
new = column * [0] + [1, 1] + (size - column - 2) * [0]
column += 2
lines.append(new)
mat = matrix(lines)