ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 19 May 2019 17:23:51 -0500How well print a list of matrices ?http://ask.sagemath.org/question/10529/how-well-print-a-list-of-matrices/In a program, I use the function "print" for printing lists of matrices.
Unfortunately, the displaying is not as well as it could, see the following example :
sage: MM=[identity_matrix(QQ,3) for i in range(3)]
sage: MM
[
[1 0 0] [1 0 0] [1 0 0]
[0 1 0] [0 1 0] [0 1 0]
[0 0 1], [0 0 1], [0 0 1]
]
sage: print(MM)
[[1 0 0]
[0 1 0]
[0 0 1], [1 0 0]
[0 1 0]
[0 0 1], [1 0 0]
[0 1 0]
[0 0 1]]
> Is there a way to print a list of
> matrices as the first above ?
(Perhaps by saving it on an external file, what would be the line code for that ?)
Tue, 10 Sep 2013 01:18:10 -0500http://ask.sagemath.org/question/10529/how-well-print-a-list-of-matrices/Answer by tmonteil for <p>In a program, I use the function "print" for printing lists of matrices. <br/>
Unfortunately, the displaying is not as well as it could, see the following example : </p>
<pre><code>sage: MM=[identity_matrix(QQ,3) for i in range(3)]
sage: MM
[
[1 0 0] [1 0 0] [1 0 0]
[0 1 0] [0 1 0] [0 1 0]
[0 0 1], [0 0 1], [0 0 1]
]
sage: print(MM)
[[1 0 0]
[0 1 0]
[0 0 1], [1 0 0]
[0 1 0]
[0 0 1], [1 0 0]
[0 1 0]
[0 0 1]]
</code></pre>
<blockquote>
<p>Is there a way to print a list of
matrices as the first above ? </p>
</blockquote>
<p>(Perhaps by saving it on an external file, what would be the line code for that ?)</p>
http://ask.sagemath.org/question/10529/how-well-print-a-list-of-matrices/?answer=15439#post-id-15439You can do:
sage: print sage.misc.displayhook.format_obj(MM)
[
[1 0 0] [1 0 0] [1 0 0]
[0 1 0] [0 1 0] [0 1 0]
[0 0 1], [0 0 1], [0 0 1]
]
You can also have a look at [this question](http://ask.sagemath.org/question/2292/how-are-list-of-matrices-printed-by-sage).
Tue, 10 Sep 2013 01:33:02 -0500http://ask.sagemath.org/question/10529/how-well-print-a-list-of-matrices/?answer=15439#post-id-15439Comment by slelievre for <p>You can do:</p>
<pre><code>sage: print sage.misc.displayhook.format_obj(MM)
[
[1 0 0] [1 0 0] [1 0 0]
[0 1 0] [0 1 0] [0 1 0]
[0 0 1], [0 0 1], [0 0 1]
]
</code></pre>
<p>You can also have a look at <a href="http://ask.sagemath.org/question/2292/how-are-list-of-matrices-printed-by-sage">this question</a>.</p>
http://ask.sagemath.org/question/10529/how-well-print-a-list-of-matrices/?comment=46585#post-id-46585@Daniel Krenn - try this instead
sage: l = [identity_matrix(QQ, 2) for _ in range(3)]
sage: from sage.repl.display.formatter import SagePlainTextFormatter
sage: f = SagePlainTextFormatter()
sage: f(l)
'[\n[1 0] [1 0] [1 0]\n[0 1], [0 1], [0 1]\n]'
sage: print(f(l))
[
[1 0] [1 0] [1 0]
[0 1], [0 1], [0 1]
]Sun, 19 May 2019 17:23:51 -0500http://ask.sagemath.org/question/10529/how-well-print-a-list-of-matrices/?comment=46585#post-id-46585Comment by Daniel Krenn for <p>You can do:</p>
<pre><code>sage: print sage.misc.displayhook.format_obj(MM)
[
[1 0 0] [1 0 0] [1 0 0]
[0 1 0] [0 1 0] [0 1 0]
[0 0 1], [0 0 1], [0 0 1]
]
</code></pre>
<p>You can also have a look at <a href="http://ask.sagemath.org/question/2292/how-are-list-of-matrices-printed-by-sage">this question</a>.</p>
http://ask.sagemath.org/question/10529/how-well-print-a-list-of-matrices/?comment=34355#post-id-34355Seems to not be possible anymore (in SageMath 7.2)Sat, 06 Aug 2016 09:57:47 -0500http://ask.sagemath.org/question/10529/how-well-print-a-list-of-matrices/?comment=34355#post-id-34355