2 回答

TA貢獻1868條經(jīng)驗 獲得超4個贊
這會重現(xiàn)您的錯誤消息。您應該顯示完整的消息,包括回溯。它包含對您和我們都很有價值的信息!
In [332]: np.empty(3)[0,:]
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-332-c37e54b88567> in <module>
----> 1 np.empty(3)[0,:]
IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed
你定義一個一維數(shù)組
size_arr = np.empty(shape=(len(business_date_list)))
并嘗試將其索引為 2d
size_arr[i,:] = news

TA貢獻1799條經(jīng)驗 獲得超6個贊
索引不是問題,而是正確調(diào)整大小
shape = ((len(business_date_list)),500)
size_arr = np.empty(shape=(shape))
y_arr = np.empty(shape=(shape))
news = np.empty(shape=(500))
#newy = np.empty(shape=(500,))
for b in range(0, len(business_date_list)):
news = model_data['size'].loc[(model_data['date'] == business_date_list[b])]
c = 500-len(news)
news = np.pad(news, (0,c), 'empty')
size_arr[b,:] = news
newy = model_data['changeday'].loc[(model_data['date'] == business_date_list[b])]
d = 500-len(newy)
newy = np.pad(newy, (0,d), 'empty')
y_arr[b,:] = newy
添加回答
舉報