如何通过 sympy 在 ipython notebook 中漂亮地打印? [英] How to pretty print in ipython notebook via sympy?

查看:28
本文介绍了如何通过 sympy 在 ipython notebook 中漂亮地打印?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过pprintprint,前者只打印Unicode版本,后者不做漂亮的打印.

I tried pprint, print, the former only prints Unicode version, and the latter doesn't do pretty prints.

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)

推荐答案

你需要使用display:

you need to use display:

from IPython.display import display

display(yourobject)

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

It will choose the appropriate representation (text/LaTex/png...), in recent enough version of IPython (6.0+) display is imported by default, still we recommend to explicitly import it.

这篇关于如何通过 sympy 在 ipython notebook 中漂亮地打印?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆