Paul Zimmermann wrote: > Hi, > > I got the following error in a Sage program I wrote: > > TypeError: unsupported operand parent(s) for '*': 'Full MatrixSpace of 2 by 1 > dense matrices over Integer Ring' and 'Full MatrixSpace of 2 by 2 dense > matrices over Rational Field' > > for the following instruction: > > --> 152 vA = v.transpose() * invA > > Here, v is a vector of dimension n, and invA is a n x n matrix. > > In mathematics, a vector of dimension n is usually considered as a n x 1 > matrix, thus to multiply it to the left of a n x n matrix, one has first > to transpose it. > > sage: m = matrix(SR,[[a,b],[c,d]]); m > > [a b] > [c d] > > sage: v = vector(SR, [d,e]); v > (d, e) > > sage: m * v > (a*d + e*b, c*d + e*d) > > sage: v.transpose() * m > --------------------------------------------------------------------------- > TypeError Traceback (most recent call last) > > /users/cacao/zimmerma/.sage/temp/patate.loria.fr/9803/_users_cacao_zimmerma_Adm_Cacao_ANC_Hadamard_algo2_sage_6.py > in <module>() > > /usr/local/sage-3.4-core2/sage/local/lib/python2.5/site-packages/sage/structure/element.so > in sage.structure.element.Matrix.__mul__ (sage/structure/element.c:11263)() > > /usr/local/sage-3.4-core2/sage/local/lib/python2.5/site-packages/sage/structure/coerce.so > in sage.structure.coerce.CoercionModel_cache_maps.bin_op > (sage/structure/coerce.c:5848)() > > TypeError: unsupported operand parent(s) for '*': 'Full MatrixSpace of 2 by 1 > dense matrices over Symbolic Ring' and 'Full MatrixSpace of 2 by 2 dense > matrices over Symbolic Ring' > > but v * m works: > > sage: v * m > (a*d + e*c, b*d + e*d)
When you just do v*m or m*v, m acts on the vector in the "obvious" way (i.e., in v*m, v is considered a row vector, while in m*v, v is considered a column vector). For me, that means I often do not have to think about "row" versus "column" vectors. To further explain William's post: matrix(v) gives a 1xn matrix (so vectors are naturally row vectors) v.transpose() is the same as matrix(v).transpose(), giving an nx1 matrix I wish vectors were considered column vectors, but I think it's probably too late to change that. The issue has come up before, and I imagine it will come up again. This issue also affects the kernel, nullspace, and other functions (which are all left kernels, left nullspaces, etc.). Some people are working on making these functions explicit (i.e., left_kernel/right_kernel, left_nullspace/right_nullspace, etc.). However, having m*v work as if v was a column vector takes care a lot of my complaints on this issue. Having right_* functions for everything will take care of most of the rest of my complaints. Jason --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---