我试过 pprint , print ,前者只打印Unicode版本,后者不做 pretty-print 。

from sympy import symbols, Function
import sympy.functions as sym
from sympy import init_printing
init_printing(use_latex=True)
from sympy import pprint
from sympy import Symbol

x = Symbol('x')

# If a cell contains only the following, it will render perfectly.
(pi + x)**2

# However I would like to control what to print in a function,
# so that multiple expressions can be printed from a single notebook cell.
pprint((pi + x)**2)

最佳答案

你需要使用显示:

from IPython.display import display

display(yourobject)

它将选择适当的表示(text/LaTex/png...),在最近的足够版本的 IPython (6.0+) 中默认导入显示,但我们仍然建议显式导入它。

关于python - 如何通过 sympy 在 ipython notebook 中漂亮地打印?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20979993/

10-15 20:26