s = self.ps*self.skip + self.Ck-1 + self.h-1 num_time_steps = 5 X1 = np.zeros((self.n-s, self.w, self.m)) X2 = np.zeros((self.n-s, self.ps*self.Ck, self.m)) Y = np.zeros((self.n-s-num_time_steps+1, num_time_steps*self.m)) for i in range(s, self.n): t = i-self.h+1 X1[i-s] = self.raw[t-self.w:t].copy() idx = [] for k in range(self.ps): idx = list(range(t-self.Ck-k*self.skip, t-k*self.skip)) + idx idx = np.array(idx, dtype=int) X2[i-s] = self.raw[idx].copy() for i in range(s+num_time_steps-1, self.n): Y[i-s-num_time_steps+1] = self.raw[i-num_time_steps+1:i+1].copy().flatten() Y = Y[:, -5*self.m:]
时间: 2024-01-25 07:05:23 浏览: 79
self-taugh.rar_UFLDL_self_self taugh
我发现这段代码中有两个 for 循环都使用了变量名 i,这可能会导致其中一个循环的结果被覆盖,从而出现错误。你可以尝试将其中一个循环的变量名改为其他名称,例如:
```
s = self.ps*self.skip + self.Ck-1 + self.h-1
num_time_steps = 5
X1 = np.zeros((self.n-s, self.w, self.m))
X2 = np.zeros((self.n-s, self.ps*self.Ck, self.m))
Y = np.zeros((self.n-s-num_time_steps+1, num_time_steps*self.m))
for i in range(s, self.n):
t = i-self.h+1
X1[i-s] = self.raw[t-self.w:t].copy()
idx = []
for k in range(self.ps):
idx = list(range(t-self.Ck-k*self.skip, t-k*self.skip)) + idx
idx = np.array(idx, dtype=int)
X2[i-s] = self.raw[idx].copy()
for j in range(s+num_time_steps-1, self.n):
Y[j-s-num_time_steps+1] = self.raw[j-num_time_steps+1:j+1].copy().flatten()
Y = Y[:, -5*self.m:]
```
这样修改后,两个循环的变量名就不会冲突了,可以避免一些潜在的错误。
阅读全文