我在 for 循環中的每次迭代中創建一個大小為 numpy 的數組20x30x30x3。我想將所有這些 numpy 數組連接成一個更大的數組。如果迭代步驟是 100,那么我想要的 numpy 數組應該是2000x30x30x3. 我嘗試使用列表:new_one_arr1_list = []new_one_arr2_list = []all_arr1 = np.array([])for item in one_arr1: # 100 iterations item = np.reshape(item, (1, 30, 30, 3)) new_one_arr1 = np.repeat(item, 20, axis=0) all_arr1 = np.concatenate(([all_arr1 , new_one_arr1 ])) ind = np.random.randint(one_arr2.shape[0], size=(20,)) new_one_arr2= one_arr1[ind] new_one_arr1_list.append(new_one_arr1) new_one_arr2_list.append(new_one_arr2)在每個迭代步驟中new_one_arr1,new_one_arr2它們都有 size 20x30x30x3。最后,當我轉換時new_one_arr1_list,new_one_arr2_list它的大小是100x20x30x30x3. 我怎么能在一個 numpy 數組中最后有 2000x30x30x3?編輯:我嘗試使用 concatenate 在一個 numpy 數組中添加數組all_arr1:all_arr1= np.concatenate(([all_arr1, new_one_arr1]))但是,我收到了消息:ValueError:所有輸入數組必須具有相同的維數
添加回答
舉報
0/150
提交
取消