天天看点

Jupyter Notebook中显示图像和数学公式

1. 可以使用LaTeX表示数学公式

# 可以使用LaTeX表示数学公式
from IPython.display import Latex
Latex(r"$\sqrt{x^2+y^2}$")      

2. SymPy的表达式也可以显示为LaTex

%load_ext sympyprinting
from sympy import *
x, y = symbols("x,y")
sqrt(x**2+y**2)      

3.  用Image类显示”jupyter.png”图片,缺省路径为Notebook文件所在的目录

from IPython.display import Image
Image(filename="jupyter.png")      

4. 使用matplotlib绘图

%matplotlib inline
plot(random.randn(100));%matplotlib inline
plot(random.randn(100));      

5. %prun用于代码的执行性能分析,可以作为行命令和单元命令使用

%%prun
for i in range(100):
    np.linalg.det(random.rand(10,10))