首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

Python教程

Jupyter技巧

安装

安装

启动,在命令行窗口,进入你工作文件夹,输入

编辑模式和命令模式

编辑模式(右上角有一个笔的图标)下按ESC切换到命令模式。

命令模式下按"回车"或双击切换到编辑模式。

命令模式下的操作:

保存: s

单元格cell

Shift+Enter 或Ctrl+Enter 执行cell

Shift+J或shift+下箭头向下选择多个cell, Shift+K或shift+上箭头向上选择多个cell, Shift+M合并选择的多个cell

添加cell: a 或b

删除cell :两个字母dd

cell之间移动:j,k

Markdown 单元格高级用法

可接受html,比如插入一幅图像:

arkdown 单元格还支持 LaTex 语法。例如:

markdown 单元格还支持 LaTex 语法。例如:

导出功能

notebook 还有一个强大的特性,就是其导出功能。可以将 notebook 导出为多种格式:

HTML

Markdown

ReST

PDF(通过 LaTeX)

Raw Python

导出 PDF 功能,可以让你不用写 LaTex 即可创建漂亮的 PDF 文档。你还可以将 notebook 作为网页发布在你的网站上。甚至,你可以导出为 ReST 格式,作为软件库的文档。

Matplotlib 集成

需要引入

下列代码将产生将绘制方程式 y=x^2 图形.

In[10]:

%matplotlibinline

importmatplotlib.pyplotasplt

importnumpyasnp

x=np.arange(20)

y=x**2

plt.plot(x,y)

Out[10]:

[]

In[9]:

1+2

Out[9]:

3

其他技巧

Checkpoints

To create a new checkpoint for your notebook select menu item Save and Checkpoint from the File menu. The checkpoint is created and the notebook file is saved. If you want to go back to that checkpoint at a later point in time you need to select the corresponding checkpoint entry from menu File → Revert to Checkpoint.

向jupyter notebook中导入python文件

或load一个网址中的py文件

jupyter中运行python文件

时间:%%time 和 %timeit

%%time 将会给出cell的代码运行一次所花费的时间。

In[13]:

%%time

importtime

for_inrange(1000):

time.sleep(0.01)# sleep for 0.01 seconds

Wall time: 10.3 s

%timeit 使用Python的timeit模块,它将会执行一个语句100,000次(默认情况下),然后给出运行最快3次的平均值。

非本地内核

你的notebook 通常是在本机运行的,你可以在浏览器上打开 http://localhost:8888/ ,从而访问 notebook。你也可以修改下配置,让该 notebook 可以被公开访问。这样,任何知道 notebook 地址的人都可以连接到 notebook 进行远程修改。

参考

Getting Started With Jupyter Notebook for Python

Jupyter Notebook基本操作介绍

http://codingpy.com/article/getting-started-with-jupyter-notebook-part-2/

Jupyter Notebook 快捷键使用指南

  • 发表于:
  • 原文链接http://kuaibao.qq.com/s/20180404G1LBGJ00?refer=cp_1026
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券