[英]Pandas ValueError: Buffer has wrong number of dimensions (expected 1, got 2)
[英]pandas: Buffer has wrong number of dimensions (expected 1, got 2) when using hstack
我正在嘗試使用 np.hstack 一些值。 但是我收到以下錯誤:
Buffer has wrong number of dimensions (expected 1, got 2)
我堆疊的行是:
s= np.hstack((np.array([cell_name, freq]).reshape((1,-1)),pred,y1_a,y1_b,y1_c,y2_a,y2_b,y2_c,y3_a,y3_b,y3_c,df[output_name].iloc[i].values.reshape(1,-1)))
我檢查了數組中每個元素的形狀,它們都具有相同的第一個維度 1。有什么想法嗎?
ps:我正在嘗試處理的dataframe的長度是2,這個堆疊是在for循環中完成的,如下所示:
for i in range(df.values.shape[0]):
s= np.hstack((np.array([cell_name, freq]).reshape((1,-1)),pred,y1_a,y1_b,y1_c,y2_a,y2_b,y2_c,y3_a,y3_b,y3_c,df[output_name].iloc[i].values.reshape(1,-1)))
您必須更詳細地調試。 您可以盡可能長時間地嘗試hstack
。 某處輸入必須是二維的。
我想你可以試試這個。
for i in reange(df.shape[0]):
my_list = [np.array([cell_name, freq]).reshape((1,-1)), pred, y1_a, y1_b, y1_c, y2_a, y2_b, y2_c, y3_a, y3_b, y3_c, df[output_name].iloc[i].values.reshape(1,-1)]
for j in range(len(my_list)):
print(f'run: {j}')
print(my_list[j].shape)
tup = tuple(my_list[:j])
s = np.hstack(tup)
如果這不起作用,您應該發布 numpy arrays。 也許您可以創建一個不起作用的最小示例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.