我想对维纳过程建模,我想添加一些基本结果实现,所以我想写这样的东西:
# 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
不支持这种情况。如何实施?
也许可以清楚了解种子的工作原理。
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])
每次您想要相同的结果时,都必须再次重置种子。