Last active
December 30, 2015 02:09
-
-
Save xccds/7761195 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 加载库 | |
import numpy as np | |
import pandas as pd | |
from ggplot import * | |
# 生成二维随机游走数据 | |
def walk(n): | |
NS = randint(0,2,size=n) | |
WE = 1 - NS | |
xstep = np.random.choice([1,-1],size=n,replace=True) * WE | |
ystep = np.random.choice([1,-1],size=n,replace=True) * NS | |
x = cumsum(xstep) | |
y = cumsum(ystep) | |
return array([x,y]) | |
res = walk(2**12) | |
# 将结果转为dataframe | |
data = pd.DataFrame({'x':res[0],'y':res[1]}) | |
# 结果绘图 | |
ggplot(aes(x='x', y='y'), data=data) + geom_line() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment