[云炬python3玩转机器学习笔记] 3-2 Jupter Notebook魔法命令

 

xxxxxxxxxx
 

### %run
%run¶
In [1]:


 

%run myscript/hello.py
hello Machine Learning !
. . .

In [2]:


xxxxxxxxxx
 

hello("天剑云炬网络科技有限公司")
hello 天剑云炬网络科技有限公司 !
. . .

In [3]:


xxxxxxxxxx
 

import mymodule.FirstML
. . .

In [4]:


xxxxxxxxxx
 

mymodule.FirstML.predict(1)
?
. . .

In [5]:


xxxxxxxxxx
 

from mymodule import FirstML
​
FirstML.predict(2)
?
. . .

xxxxxxxxxx
 

### %timeit
%timeit¶
In [6]:


x
%timeit L=[i**2 for i in range(1000)]
492 µs ± 62 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
. . .

In [7]:


x
%timeit L=[i**2 for i in range(1000000)]
561 ms ± 87.9 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
. . .

In [8]:


xxxxxxxxxx
 

%timeit L=[i**2 for i in range(10)]
4.89 µs ± 711 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
. . .

In [9]:


x
%%timeit
L = []
for n in range(1000):
    L.append(n ** 2)
532 µs ± 53.6 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
. . .

xxxxxxxxxx
 

### %time
%time¶
In [10]:


 

%time L=[i**2 for i in range(1000)]
Wall time: 1 ms
. . .

In [11]:


 

%%time
L = []
for n in range(1000):
    L.append(n ** 2)
Wall time: 1 ms
. . .

In [12]:


x
 

import random
L= [random.random() for i in range(100000)]
%timeit L.sort()
1.05 ms ± 141 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
. . .

In [13]:


x
import random
L= [random.random() for i in range(100000)]
%time L.sort()
Wall time: 26 ms
. . .

In [14]:


 

%time L.sort()
Wall time: 3 ms
. . .

xxxxxxxxxx
 

### 其他魔法命令
其他魔法命令¶
In [15]:


 

%lsmagic
Out[15]:

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.
. . .

In [16]:


xxxxxxxxxx
 

%run?
. . .

In [ ]:


 

​
. . .

 

Guess you like

Origin blog.csdn.net/qq_39154376/article/details/121384688