python 随机漫步

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 随机漫步相关的知识,希望对你有一定的参考价值。

# Numpy is imported; seed is set

# Initialize all_walks
all_walks = []

# Simulate random walk 10 times
for i in range(10):

    # Code from before
    random_walk = [0]
    for x in range(100) :
        step = random_walk[-1]
        dice = np.random.randint(1,7)

        if dice <= 2:
            step = max(0, step - 1)
        elif dice <= 5:
            step = step + 1
        else:
            step = step + np.random.randint(1,7)
        random_walk.append(step)

    # Append random_walk to all_walks
    all_walks.append(random_walk)

# Print all_walks
print(all_walks)

以上是关于python 随机漫步的主要内容,如果未能解决你的问题,请参考以下文章

醉汉随机行走/随机漫步问题(Random Walk Drunk Python)

python 实现随机漫步

python应用-随机漫步

python Python - 随机漫步

python数据可视化--matplotlib进行随机漫步

python 随机漫步