Ask Your Question
0

Anything similar to MatrixForm

asked 0 years ago

akm gravatar image

Hi, is there anything similar to Mathematica's MatrixForm for pretty printing vectors and matrices?

Preview: (hide)

Comments

Does "show" suit your needs?:

m=matrix([[1,2,3],[4,5,6]])
show(m)
tolga gravatar imagetolga ( 0 years ago )

2 Answers

Sort by » oldest newest most voted
0

answered 0 years ago

Emmanuel Charpentier gravatar image

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...

Preview: (hide)
link
0

answered 0 years ago

akm gravatar image

Beautiful thank you; is there an option to display a vector vertically?

Preview: (hide)
link

Comments

Oh nevermind I got what I needed with .transpose()

akm gravatar imageakm ( 0 years ago )

Please try this:

v=vector([1,2,3])
show(v.column())
tolga gravatar imagetolga ( 0 years ago )

Yeah works great, thanks @tolga

akm gravatar imageakm ( 0 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 0 years ago

Seen: 243 times

Last updated: Jul 27 '24