Ask Your Question
0

Anything similar to MatrixForm

asked 2024-07-26 19:11:32 +0100

akm gravatar image

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

edit retag flag offensive close merge delete

Comments

Does "show" suit your needs?:

m=matrix([[1,2,3],[4,5,6]])
show(m)
tolga gravatar imagetolga ( 2024-07-26 19:32:37 +0100 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2024-07-27 09:17:05 +0100

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

edit flag offensive delete link more
0

answered 2024-07-26 19:54:06 +0100

akm gravatar image

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

edit flag offensive delete link more

Comments

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

akm gravatar imageakm ( 2024-07-26 19:58:37 +0100 )edit

Please try this:

v=vector([1,2,3])
show(v.column())
tolga gravatar imagetolga ( 2024-07-26 20:00:23 +0100 )edit

Yeah works great, thanks @tolga

akm gravatar imageakm ( 2024-07-26 20:22:03 +0100 )edit

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: 2024-07-26 19:11:32 +0100

Seen: 221 times

Last updated: Jul 27