Python Sympy 漂亮的矩阵输出
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]])
我认为矩阵太大,无法很好地打印到控制台。我对 numpy 也有同样的问题。我可以用 np.set_printoptions(suppress=True,linewidth=10000)
修复它。我怎样才能用 sympy 解决这个问题?
尝试从 sympy pprint
:
>>> 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)⎦
来自文档(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()
.
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]])
我认为矩阵太大,无法很好地打印到控制台。我对 numpy 也有同样的问题。我可以用 np.set_printoptions(suppress=True,linewidth=10000)
修复它。我怎样才能用 sympy 解决这个问题?
尝试从 sympy pprint
:
>>> 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)⎦
来自文档(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, theinit_session()
function will automatically import everything in SymPy, create some common Symbols, setup plotting, and runinit_printing()
.