浅鱼

jupyter魔法命令
jupyter魔法命令%run%run /Users/tiramisu/Desktop/test.pyhello ...
扫描右侧二维码阅读全文
06
2018/08

jupyter魔法命令

jupyter魔法命令

%run

%run /Users/tiramisu/Desktop/test.py

hello python!

%load

# %load test.py
print('hello python!') 

hello python!

import my.demo
my.demo.show('梓逸宸')

梓逸宸

from my.demo import show
show('过往云烟')

过往云烟

%timeit

%timeit 计算一行命令的运算时间

%%timeit 计算一个代码段的运行时间

%timeit li = [i**2 for i in range(1000)]

341 µs ± 9.32 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)

%timeit li = [i**2 for i in range(1000000)]

368 ms ± 11.8 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

%timeit li = [i**2 for i in range(10)]

3.72 µs ± 193 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)

%%timeit
li = []
for i in range(1000):
    li.append(i**2)

411 µs ± 5.01 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)

%time

%time 无论什么代码,都只执行一遍 1 loop each

%%time 计算代码段执行一遍的时间

%time li = [i**2 for i in range(1000)]

CPU times: user 365 µs, sys: 0 ns, total: 365 µs
Wall time: 371 µs

%%time
li = []
for i in range(1000):
    li.append(i**2)

CPU times: user 527 µs, sys: 1e+03 ns, total: 528 µs
Wall time: 536 µs

import random
li = [random.random() for i in range(1000)]
%timeit li.sort()

18.5 µs ± 509 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)

li = [random.random() for i in range(1000)]
%time li.sort()

CPU times: user 373 µs, sys: 57 µs, total: 430 µs
Wall time: 396 µs

%time li.sort()

CPU times: user 30 µs, sys: 0 ns, total: 30 µs
Wall time: 33.9 µs

%%html

%%html
<div class="mytest" style="color: cyan">梓逸宸</div>

<div class="mytest" style="color: cyan">梓逸宸</div>

%%js

%%js
document.querySelector(".mytest").innerHTML = "红豆生南国";

<IPython.core.display.Javascript object>

!

! 可以执行系统命令

! cd /Users/tiramisu/Desktop/ && ls
$RECYCLE.BIN
2018年创新创业--机票比较系统的替身
7.18直播截屏
OneDrive - csu.edu.cn
Thumbs.db
desktop.ini
html笔记截屏
job
jsp
me.jpeg
my
test.py
www.runtofuture.cn.zip
~$系统课设设计.docx
速云
全校st-id
牛客网--写简历
优秀文章
屏幕快照 2018-06-22 下午3.03.32.png
屏幕快照 2018-07-03 下午3.39.58.png
屏幕快照 2018-07-07 上午9.07.46.png
屏幕快照 2018-08-06 下午2.42.57.png
屏幕快照 2018-08-06 下午2.43.00.png
屏幕快照 2018-08-06 下午2.45.02.png
屏幕快照 2018-08-06 下午2.49.00.png
屏幕快照 2018-08-06 下午2.52.04.png
屏幕快照 2018-08-06 下午2.52.09.png
屏幕快照 2018-08-06 下午2.55.15.png
屏幕快照 2018-08-06 下午2.55.48.png
屏幕快照 2018-08-06 下午2.56.43.png
求职技巧.pptx
全校部分js-id
桌面文件夹

%%writefile

%%writefile new_test.py
li = []
for i in range(1000):
    li.append(i**2)

Writing new_test.py

! ls
Application Data              PycharmProjects
Applications                  QQ-cloud
Applications (Parallels)      Qt5.8.0
CLionProjects                 QtProject
Desktop                       System Volume Information
Docker                        Workgroup
Documents                     bin
Downloads                     eclipse-workspace
Google-cloud-disk             iCloud 云盘(归档)
HBuilder                      iCloud 云盘(归档) - 1
HBuilderProjects              iCloud 云盘(归档) - 2
Hexo                          iCloud 云盘(归档) - 3
IdeaProjects                  jupyter_note.ipynb
Kingsoft                      my
Library                       new_test.py
Movies                        nodePipe1827.sock
Music                         nodePipe5558.sock
OneDrive - csu.edu.cn         node_modules
Parallels                     python_work
Pictures                      venv
Public                        webui-aria2
! cat new_test.py
li = []
for i in range(1000):
    li.append(i**2)
Last modification:August 6th, 2018 at 04:27 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment