I've got a set of 6 equations that I'd like numpy to solve for me. So I construct a 6x6 matrix of coefficients, and fill it in with various values. However, the code I end up writing to do this is quite illegible, and conveys little about the equations that I want to solve to the reader of my code.
For example, filling out the coefficients matrix looks something like this:
# Coefficients matrix
# Order of variables: w, X, Y, Z, s, t
A = np.mat( np.zeros((6,6)) )
A[0:3,0] = cam_inv[...,2]
A[0:3,1:4] = -np.identity(3)
A[3:6,1:4] = np.identity(3)
A[3:,4] = -eigvecs[...,0]
A[3:,5] = -eigvecs[...,1]
# Constants matrix (RHS of equation)
b = np.mat( np.zeros((6,1)) )
b[0:3,0] = -cam_inv[...,0:2] * point
b[3:,] = mean.T
res = np.linalg.solve(A,b)
(Where cam_inv, eigvecs, mean, and point are some other matrices computed elsewhere.)
Obviously the above code could have some more comments, but I feel that even with some comments, it'd still fail to really convey the underlying equations that are being solved. Is there a better way of feeding equations into the solver that results in code that is more legible?