Ask Your Question
2

How to change width of output in sagemath notebook?

asked 2020-06-03 19:18:11 +0100

Dominik Stępień gravatar image

updated 2024-04-22 20:26:32 +0100

FrédéricC gravatar image

I am working with big matrices and when I want to print them rows of matrix don't fit in one line of output and it is broken up although there is space on the screen left. Such printing makes matrix unreadable is there anyway to change this?

edit retag flag offensive close merge delete

Comments

Can you provide a minimal example? For instance a matrix with one row and the least number of columns to illustrate the issue.

slelievre gravatar imageslelievre ( 2020-06-04 00:59:19 +0100 )edit

1 Answer

Sort by » oldest newest most voted
2

answered 2020-06-08 00:00:45 +0100

mwageringel gravatar image

There are several options that may be useful when working with large matrices.

According to this answer, you can make the output cells as wide as your browser window like this:

from IPython.core.display import display, HTML
display(HTML("<style>.container { width:100% !important; }</style>"))

The way matrices render depends on Sage's display mode setting. You can use latex rendering which shows the matrix without wrapping, possibly with scroll bars:

%display None      # this is the default setting
show(matrix.random(RDF, 3, 6))

$\left(\begin{array}{rrrrrr} -0.5335729217418883 & 0.33189831716910057 & -0.8771148747225102 & -0.14167703358089478 & -0.03476729579811866 & -0.7426696594404245 \\ -0.5264988250426905 & -0.9613263978046536 & 0.5193318671027474 & 0.50502299085177 & 0.9965496912371574 & -0.2443527360324771 \\ -0.87630629977601 & -0.4145065008844313 & 0.11082126955236471 & 0.36141568208211927 & -0.5794258198253386 & 0.5378936808115167 \end{array}\right)$

Alternatively, to use latex rendering for everything:

%display latex
matrix.random(RDF, 3, 6)

In the terminal, you can view the latex rendered output in an external PDF viewer:

view(matrix.random(RDF, 3, 6))

As of Sage 9.1, another option is to use ascii_art or unicode_art for the display.

sage: %display unicode_art
sage: matrix.random(RDF, 3, 6)
⎛  0.7857496475272576  -0.5621432349663726  -0.6197864217688647
⎜-0.09602225319381907   0.6310818306433721  0.04663485890726049
⎝   0.364267304071475   0.8731639828344335 -0.22804442057132857

   0.2696959663485283   0.4186525964528831  -0.8423186241521643⎞
 -0.49765470886120133   0.4748930267502407   0.4784913888617619⎟
   0.6678112962808911  -0.7422772589338069   0.5578165726172355⎠

In the terminal, the above makes use of the full width of the terminal window. In the notebook, it defaults to 80 columns - you can set a higher column number like this:

sage: %display unicode_art 100
sage: matrix.random(RDF, 3, 6)
⎛ 0.41816693194292154  0.26120840306318804   -0.837348560208534 -0.45806384657796806
⎜  0.7240198735200238  -0.3906634900294397  -0.4104572268754003    0.987926730666215
⎝-0.16185556154081815 -0.03065482370398409  -0.3616997572776217  -0.8037967794680001

    0.841751537119509  -0.9660050207134228⎞
   0.8075498876793383  -0.7844231138398663⎟
   0.8499554630711053  0.18744229144965852⎠
edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2020-06-03 19:18:11 +0100

Seen: 607 times

Last updated: Jun 08 '20