2 回答
TA贡献1868条经验 获得超4个赞
这会重现您的错误消息。您应该显示完整的消息,包括回溯。它包含对您和我们都很有价值的信息!
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
你定义一个一维数组
size_arr = np.empty(shape=(len(business_date_list)))
并尝试将其索引为 2d
size_arr[i,:] = news
TA贡献1799条经验 获得超6个赞
索引不是问题,而是正确调整大小
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
添加回答
举报