Python for Data Analysis (9)
阿新 • • 發佈:2019-01-01
魔法命令
a=1;b=100
a*b
%timeit a*b
The slowest run took 15.46 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 201 ns per loop
import numpy as np
a=np.random.randn(100,100)
%timeit np.dot(a,a)
%time np.dot(a,a)
The slowest run took 1636.68 times longer than the fastest. This could mean that an intermediate result is being cached. 10000 loops, best of 3: 46.3 µs per loop CPU times: user 93 µs, sys: 1e+03 ns, total: 94 µs Wall time: 73 µs array([[ 1.6460291 , 8.04479056, 3.55858006, ..., -5.11887218, -2.34480825, 0.29470307], [ -2.31945251, -19.91884282, -16.80738536, ..., -5.11245243, 5.26080793, 2.11886289], [ 3.14523094, 10.21521818, 9.28415132, ..., -8.38065148, 17.53078937, -7.68667463], ..., [ 13.92807526, 13.70927476, -14.50414208, ..., 0.71719941, 6.33660503, -6.9980424 ], [ 9.13700782, 1.43313504, -1.26994739, ..., 8.07787293, 14.41700316, 5.32727609], [ 1.38417926, 17.93342167, 2.68956568, ..., -11.20007195, -14.31456352, 4.74833645]])
插入圖片
from IPython.display import Image
Image(filename="pic/magic1.png")
Image(filename="pic/magic2.png")
插入Latex
from IPython.display import Latex
Latex("$Z=\sqrt{x^2+y^2}$")
%hist #檢視歷史輸入
%logstart #日誌記錄開始,有一個系列:%logoff,logon,logstate,logstop
Activating auto-logging. Current session state plus future input saved. Filename : #日誌記錄開始,有一個系列:%logoff,logon,logstate,logstop Mode : backup Output logging : False Raw input log : False Timestamping : False State : active
%logoff #日誌記錄結束
Switching logging OFF
Image('pic/magic3.png') #其中帶!的命令表示是其後面的內容需要在系統shell中執行,這個很厲害,打通了Ipython和shell的溝通
Image('pic/magic4.png')
#%alias ,可以為shell命令自定義簡稱
%alias ll ls -l
ll
total 162160
-rw-r--r-- 1 momo staff 636 9 19 21:25 #日誌記錄開始,有一個系列:%logoff,logon,logstate,logstop
-rw-r--r-- 1 momo staff 1414 9 9 16:02 Python for Data Analysis (1).ipynb
-rw-r--r-- 1 momo staff 13654 9 11 11:39 Python for Data Analysis (2).ipynb
-rw-r--r-- 1 momo staff 5288 9 11 23:38 Python for Data Analysis (3).ipynb
-rw-r--r-- 1 momo staff 7618 9 12 10:09 Python for Data Analysis (4).ipynb
-rw-r--r-- 1 momo staff 5462 9 12 22:38 Python for Data Analysis (5).ipynb
-rw-r--r-- 1 momo staff 3284 9 13 23:49 Python for Data Analysis (6).ipynb
-rw-r--r-- 1 momo staff 4815 9 16 09:36 Python for Data Analysis (7).ipynb
-rw-r--r-- 1 momo staff 6022 9 19 19:36 Python for Data Analysis (8).ipynb
-rw-r--r-- 1 momo staff 714346 9 19 21:29 Untitled.ipynb
-rw-r--r-- 1 momo staff 1020 9 19 21:15 ipython_log.py
drwxr-xr-x 6 momo staff 204 9 19 21:17 [34mpic[m[m
[email protected] 1 momo staff 82233792 9 19 2015 [31m利用Python進行資料分析.pdf[m[m
#還可以一次性定義多條為一個命令!!!太牛了
#只需用分號將多個命令隔開
%alias test_alias (cd pic;ls)
%test_alias
magic1.png magic2.png magic3.png magic4.png