Christofer Iacovou
Christofer Iacovou

Reputation: 53

Sympy pretty print matrix

I am using sympy to do symbolic matrix multiplication of 13 2x2 matrices (for optics). The resulting matrix is of course a 2x2 matrix but is huge.

I am using pprint() in order to display stuff in a nice manner. Problem is that pprint is basically "splitting" the matrix over many rows making it basically unreadable. To put things into perspective, below is the first element of the matrix as it is pretty printed, so imagine how the whole thing is going to look like.

enter image description here

Any tips, tricks to pretty print the matrix in a continuous way?

Many thanks,

P.S; I am using jupyter notebook

Upvotes: 2

Views: 1899

Answers (1)

Cedric
Cedric

Reputation: 446

This is probably a little late. After over an hour searching for this tiny problem, I finally found a fix: As stated in their internal documentation for pretty_print (pprint is essentially a wrapper for this):

num_columns : int or None, optional (default=None)
        Number of columns before line breaking (default to None which reads
        the terminal width), useful when using SymPy without terminal.

I would recommend setting the limit to something you will never exceed, e.g. 10,000 or even 100,000. This at least worked for me:

pprint(expression, num_columns=10_000)

Upvotes: 1

Related Questions