jupyter notebook learning
a very simple operation
Let’s add two numbers
1+2
3
Counter
Let’s count from 0 to 4
for i in range(6):
print(i)
0
1
2
3
4
5
plot y = x^2
%matplotlib inline
%config InlineBackend.figure_format = 'svg' # 渲染矢量图使图片更加清晰
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(20)
y=x**(2)
plt.plot(x,y)
[<matplotlib.lines.Line2D at 0x26d760a5208>]
魔法指令查询
%lsmagic
Available line magics:
%alias %alias_magic %autoawait %autocall %automagic %autosave %bookmark %cd %clear %cls %colors %conda %config %connect_info %copy %ddir %debug %dhist %dirs %doctest_mode %echo %ed %edit %env %gui %hist %history %killbgscripts %ldir %less %load %load_ext %loadpy %logoff %logon %logstart %logstate %logstop %ls %lsmagic %macro %magic %matplotlib %mkdir %more %notebook %page %pastebin %pdb %pdef %pdoc %pfile %pinfo %pinfo2 %pip %popd %pprint %precision %prun %psearch %psource %pushd %pwd %pycat %pylab %qtconsole %quickref %recall %rehashx %reload_ext %ren %rep %rerun %reset %reset_selective %rmdir %run %save %sc %set_env %store %sx %system %tb %time %timeit %unalias %unload_ext %who %who_ls %whos %xdel %xmode
Available cell magics:
%%! %%HTML %%SVG %%bash %%capture %%cmd %%debug %%file %%html %%javascript %%js %%latex %%markdown %%perl %%prun %%pypy %%python %%python2 %%python3 %%ruby %%script %%sh %%svg %%sx %%system %%time %%timeit %%writefile
Automagic is ON, % prefix IS NOT needed for line magics.
魔法指令测试
%time
for x in range(100):
for y in range(1000):
pass
Wall time: 0 ns
%%timeit a=range(10)min(a)
UsageError: %%timeit is a cell magic, but the cell body is empty. Did you mean the line magic %timeit (single %)?
jupyter 快捷键记录
命令模式下的常用快捷键
-
a / b (在活跃单元格(之上/之下)) 插入一个新的单元
-
dd 删除一个单元格
-
Ctrl+d 清空单元格
-
Shift+ ↑↓可以选择多个单元,按Shift+M 合并这些单元啊
-
(m/y) MarkDown 模式/代码模式
编辑模式下常用快捷键
-
Ctrl + S 保存进度
-
Ctrl + Enter 运行代码
-
Alt + Enter 运行并在下方添加单元格