不幸的是,我很清楚这个索引错误,它只是说我超出范围。 但是我无法理解当前代码中的情况。 我尽了一切努力。 如果有人知道我应该更改以解决此问题,请提供帮助。
import numpy as np
import numpy.random as npr
j=0
T=10
M=10000
N=200
h=T/N
sigma=np.linspace(0.1,0.6,num=5)
X=np.ones(shape=(5*M,N))
X[:,0]=0.5 # X0=0.5
Z=npr.randn(M,N)
for S in range(1,6):
s=sigma[S-1]
while j<=(S*M-1): **# PROBLEM IS HERE,it fills X array rows 0-9999 and no more!**
for i in range(0,N-1):
X[j,i+1]=X[j,i]+X[j,i]*(1-X[j,i])*h+s*Z[j,i]*np.sqrt(h)
j+=1
**# supposed to take another S and keep going**