Jupyter 魔术方法

20180902

%lsmagic

查看所有魔法目录
Available line magics:
%alias %alias_magic %autocall %automagic %autosave %bookmark %cd %clear %cls %colors %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 %popd %pprint %precision %profile %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 %%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.

查看魔法命令文档

%run?

脚本文件加载

Jupyter中使用%run xxx\jupyter_magic.py 运行并加载整个python脚本到notebook。

模块加载

创建init.py 使文件夹成为模块

import mymodule.FirstML 加载模块
mymodule.FirstML.predict(1) 调用FirstML.py中的predict()函数

from mymodule import FirstML
FirstML.predict(2)

%timeit

自动选择执行次数,得到平均运行时间。
%timeit L = [i**2 for i in range(1000)]
1000 loops, best of 3: 1.32 ms per loop

o(n) 的算法复杂度

扫描二维码关注公众号,回复: 4428641 查看本文章

%%timeit

度量单元格内整体消耗的时间。

%time

测试一次执行的时间。

%%time

单元格内消耗的时间。

猜你喜欢

转载自blog.csdn.net/qq_21980099/article/details/82315266