1 | initial version |
Something like:
sage: M=matrix(3,3,[1,2,3,4,5,6,7,8,9])
sage: P=PolynomialRing(QQ,M.nrows(),names="x")
sage: (vector(P.gen(i) for i in range(3))*M).list()
[x0 + 4*x1 + 7*x2, 2*x0 + 5*x1 + 8*x2, 3*x0 + 6*x1 + 9*x2]
perhaps? It will depend on your application a bit whether you need to convert to/from lists and what kind of polynomial ring you need. A good rule of thumb is avoiding going through strings. It will be much more robust if the system knows the meaning of the objects throughout.