Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        6年前关闭。
                                                                                            
                
        
我使用以下代码生成随机游走的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中绘制此随机游走图?

最佳答案

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()

08-06 21:42