我有 x_train,這是一個屬于數據波形的數組,維度為 (475,1501),我希望最終輸出 (seg2) 為 (1425,500)。我嘗試了以下代碼:count=0sega=[]seg2=[]for i in range (0,len(x_train)): sega = x_train[i][:(x_train[i].size // 500) * 500].reshape(-1, 500) seg2[count:(count+1),500] = sega count = count + i但它抱怨以下錯誤:---------------------------------------------------------------------------TypeError Traceback (most recent call last)<ipython-input-137-72281c805a83> in <module> 10 sega = x_train[i][:(x_train[i].size // 500) * 500].reshape(-1, 500) 11 print(sega.shape)---> 12 seg2[count:(count+1),500] = sega 13 count = count + i 14 TypeError: list indices must be integers or slices, not tuple我該如何解決這個錯誤?
1 回答

翻翻過去那場雪
TA貢獻2065條經驗 獲得超14個贊
seg2是一個list。看起來您需要將其聲明為np.array. 像這樣:
seg2 = np.zeros((total_count, 500))
在哪里total_count=1425。
你也可以np.concatenate這樣使用:
seg2 = np.concatenate([
x_train[i][:(x_train[i].size // 500) * 500].reshape(-1, 500)
for i in range(0,x_train.shape[0])
], axis=0)
添加回答
舉報
0/150
提交
取消