Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Sympy Pretty Output of Matrix

Matrix([[607000, 907, 259, -2165, -1846, 185, -60, -1593, 1445, 1405], [-1000, -2, 0, -1, 0, 0, -1, 0, 0, -1], [0, 0, 1, 0, 0, 0, 0, 0, 0, 0], [-4000, -7, -3, 5, 4, 1, -1, 4, -4, -2], [-317000, -469, -128, 1173, 1001, -105, 35, 862, -772, -771], [-70000, -105, -32, 246, 209, -19, 7, 180, -166, -157], [8000, 14, 6, -10, -9, -1, -1, -8, 9, 4], [-540000, -807, -230, 1925, 1642, -166, 56, 1418, -1284, -1249], [-328000, -488, -137, 1189, 1017, -104, 36, 872, -785, -776], [-70000, -105, -31, 246, 208, -21, 6, 179, -166, -157]])

I think the matrix is too big to be pretty printed to console. I had the same problem with numpy, too. I could fix it there with np.set_printoptions(suppress=True,linewidth=10000). How can i fix this with sympy?

like image 401
user4555363 Avatar asked Feb 18 '15 21:02

user4555363


People also ask

How do I make a pretty print in SymPy?

If all you want is the best pretty printing, use the init_printing() function. This will automatically enable the best printer available in your environment. You can also change the printer used in SymPy Live. Just change the “Output Format” in the settings.

How do you transpose a matrix in SymPy?

To actually compute the transpose, use the transpose() function, or the . T attribute of matrices. Represents the trace of a matrix expression. Represents a matrix using a function ( Lambda ) which gives outputs according to the coordinates of each matrix entries.

How do you find the determinant of a matrix using SymPy in Python?

With the help of sympy. det() method, we can find the determinant of a matrix by using sympy. det() method. Return : Return determinant of a matrix.


Video Answer


1 Answers

Try pprint from sympy:

>>> from sympy import Integral, Matrix, pi, pprint
>>> from sympy.abc import x
>>> pprint(Integral(x**2, x))
  /
 |
 |  2
 | x  dx
 |
/

>>> pprint(Matrix([
...   [1/(4*pi), 1],
...   [1, f(x)]
... ]))
⎡ 1       ⎤
⎢───   1  ⎥
⎢4⋅π      ⎥
⎢         ⎥
⎣ 1   f(x)⎦

From docs(http://docs.sympy.org/latest/tutorial/printing.html):

If all you want is the best pretty printing, use the init_printing() function. This will automatically enable the best printer available in your environment.
If you plan to work in an interactive calculator-type session, the init_session() function will automatically import everything in SymPy, create some common Symbols, setup plotting, and run init_printing().

enter image description here

like image 122
ndpu Avatar answered Sep 26 '22 00:09

ndpu