Skip to main content
 首页 » 编程设计

python之在 python 中绘制随机游走

2024年11月01日9pengyingh

<分区>

我使用以下代码生成随机游走的 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) 

我如何在 2d 中绘制这个随机游走?