方向が 0 < θ < 2π で、T=1000 ステップの 2 次元ランダム ウォークをシミュレートしています。私は既に持っています:
a=np.zeros((1000,2), dtype=np.float)
def randwalk(x,y):
theta=2*math.pi*rd.rand() # Theta is a random angle between 0 and 2pi
x+=math.cos(theta); # Since spatial unit = 1
y+=math.sin(theta); # Since spatial unit = 1
return (x,y)
x, y = 0., 0.
for i in range(1000):
x, y = randwalk(x,y)
a[i,:] = x, y
これにより、単一のウォークが生成され、すべての中間座標が numpy 配列 a に格納されます。コードを編集して (毎回新しいランダム シードを使用して) ウォークを 12 回繰り返し、各ランを個別のテキスト ファイルに保存するにはどうすればよいですか? randwalk 関数内に while ループが必要ですか?
推測:
rwalkrepeat = []
for _ in range(12):
a=np.zeros((1000,2), dtype=np.float)
x, y = 0., 0.
for i in range(1000):
x, y = randwalk(x,y)
a[i,:] = x, y
rwalkrepeat.append(a)
print rwalkrepeat