是否有一些种子可供选择np.random分布?

问题描述 投票:0回答:1

我想对维纳过程建模,我想添加一些基本结果实现,所以我想写这样的东西:

# w is elementary result
def W(T, w = 0, dt = 0.001):
    x = [0]
    for t in np.arange(0, T, dt):
        x.append(x[-1] + np.random.normal(0,dt, w))
    return x

并且我希望在w相同的情况下得到W的相同输出。但是np.random.normal不支持这种情况。如何实施?

python stochastic-process
1个回答
0
投票

也许可以清楚了解种子的工作原理。

import numpy as np

np.random.seed(0)
np.random.normal(0,0.001,1)
>> array([0.00176405]) #My output
np.random.normal(0,0.001,1)
>>array([0.00040016])

np.random.seed(0)
np.random.normal(0,0.001,1)
>> array([0.00176405]) #Same output
np.random.normal(0,0.001,1)
>>array([0.00040016])

每次您想要相同的结果时,都必须再次重置种子。

© www.soinside.com 2019 - 2024. All rights reserved.