Ask Your Question
1

Nice display of a list of "matrices"

asked 2014-01-30 08:04:58 +0200

boumol gravatar image

In the context of graphs I have seen that it is possible to display in a very nice picture of all graphs in a certain list using for instance the following code:

sage: G = GraphQuery(display_cols=['graph6'], num_vertices=7, diameter=5)
sage: L = G.get_graphs_list()
sage: graphs_list.show_graphs(L)

The output one gets is the picture image description

I would like to get the same output display but this time using a diferent kind of objects (instead of graphs), namely matrices for the sake of this question. So, here is the question: suppose you have a list L of matrices, for example the one defined by

sage: L=[ MatrixSpace(ZZ,3).random_element() for i in [0..8]]

Is there some way to obtain a picture of the same kind than before except for replacing the graphs with the display of each one of the matrices in L?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
3

answered 2014-01-30 12:02:06 +0200

slelievre gravatar image

You could define a function to produce a latex array (or tabular):

def matrix_array(L,ncols):
    nl = '\n'
    s = nl + r'\begin{array}{' + ('c' * ncols) + r'}' + nl
    for k in xrange(len(L)):
        if k%ncols != 0: s += '&' + nl
        s += str(latex(L[k])) + nl
        if ((k+1)%ncols == 0) or (k == len(L)):
            s += r'\\' + nl
    s += r'\end{array}' + nl
    return LatexExpr(s)

and then view it:

sage: L = [MatrixSpace(ZZ,3).random_element() for i in [0..8]]
sage: view(matrix_array(L,ncols=3))
edit flag offensive delete link more

Comments

Thanks. Your answer has really helped me.

boumol gravatar imageboumol ( 2014-01-31 11:20:28 +0200 )edit
1

answered 2014-02-01 04:47:07 +0200

ndomes gravatar image

Just another suggestion:

L = [random_matrix(ZZ,2,2) for k in range(20)]
def list_of_lists(L,ncol):
    return [L[k:k+ncol] for k in range(0,len(L),ncol)]
html.table(list_of_lists(L,5))
edit flag offensive delete link more

Comments

Thanks. Is there some easy way to get the output in pdf format (or in png, jpg)? I ask this because later I want to use this output inside a paper I am writing using LaTeX.

boumol gravatar imageboumol ( 2014-02-03 04:07:02 +0200 )edit
1

https://bitbucket.org/whuss/sws2tex/

ndomes gravatar imagendomes ( 2014-02-03 09:07:12 +0200 )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

2 followers

Stats

Asked: 2014-01-30 08:04:58 +0200

Seen: 783 times

Last updated: Feb 01 '14