python - 用Python绘制随机游走图

标签 python

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

相关文章:

python - 如何在两个数据类之间绘制分隔线?

python - 如何在 django 1.8 中获取所有模型

Python 使用 __init__.py 从其他文件夹(同一项目内)导入文件?

python - Tensorflow 错误 : "Label IDs must < n_classes", 但我的标签 ID 似乎已经满足此要求

python - 通过 AWS lambda 在 EC2 实例上执行 python 脚本

python - 绘制 Pandas Dataframe 的直方图及其均值和标准差,得到 ValueError

file-io - 作为副作用,处理文件的类或方法是否应该关闭文件?

python - Jabber bot - 如何获取状态更新?

python - 如何替换现有方法中的函数调用

python - 一种将重复项转换为 Python 索引的优雅方法?