Anything similar to MatrixForm
Hi, is there anything similar to Mathematica's MatrixForm for pretty printing vectors and matrices?
Hi, is there anything similar to Mathematica's MatrixForm for pretty printing vectors and matrices?
I have to disagree with @tolga : a matrix is not a list of lists, it has a structure giving it specific properties. Let me illustrate :
sage: var("a, b, c, d, e, f")
(a, b, c, d, e, f)
sage: L1 = [[a, b], [c, d]]
sage: L2 = [e, f]
L1 is just a list, with no specific structure, happenning to be a list of two lists :
sage: L1
[[a, b], [c, d]]
You can create a matrix object from this list of lists with matrix
; this object is recognized as such (hence a diferent default printing format :
sage: matrix(L1)
[a b]
[c d]
Similarly, L2 is but a list :
sage: L2
[e, f]
whereas a vector
has a specific structure with specific properties (including printing) :
sage: vector(L2)
(e, f)
The multiplication of two lists has no intrinsic meaning :
sage: L1*L2
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[15], line 1
----> 1 L1*L2
TypeError: can't multiply sequence by non-int of type 'list'
whereas the product of a matrix by a vector is well defined (and results in a vector, if dimensions are compatible) :
sage: matrix(L1)*vector(L2)
(a*e + b*f, c*e + d*f)
sage: (matrix(L1)*vector(L2)).parent()
Vector space of dimension 2 over Symbolic Ring
Here, Mathematica is weaker than Sage by missing this distinction ; be smart and use Sage's strengths !
A side note : there is, mathematically speaking, no row vectors and column vectors : a vector is a vector is a vector, period. The distinction between row and columns vectors is an anglo-saxon fetish imposed upon unlucky undergrads for mistaken "pedagogical" reasons (insist on the non-commutativity of matrix and vector-matrix products, I suppose).
And, BTW, in Sage, a so-called column vector :
sage: vector(L2).column()
[e]
[f]
isn't a vector but a single-column matrix :
sage: vector(L2).column().parent()
Full MatrixSpace of 2 by 1 dense matrices over Symbolic Ring
Not a pretty sight...
Beautiful thank you; is there an option to display a vector vertically?
Please start posting anonymously - your entry will be published after you log in or create a new account.
Asked: 2024-07-26 19:11:32 +0200
Seen: 199 times
Last updated: Jul 27
Does "show" suit your needs?: