我使用以下代码生成随机游走的 y 坐标。
from random import *
n = 10
length = 100*n
def ncount(vector):
return sum(vector)
randBinList = lambda n: [randint(0,1) for b in xrange(1,n+1)]
vector = randBinList(length)
ycoords = [ncount(vector[i:i+n-1]) for i in xrange(length-n+1)]
xcoords = range(length-n+1)
如何绘制二维随机游走图?
最佳答案
from pylab import *
ycoords = [ncount(vector[i:i+n-1]) for i in xrange(length-n+1)]
xcoords = range(length-n+1)
plot(xcoords,ycoords)
show()
关于python - 用Python绘制随机游走图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20349501/