簡體   English   中英

將numpy數組列表轉換為5D numpy數組

[英]Convert a list of numpy arrays to a 5D numpy array

我有7000個對象(list_of_objects)的數據庫,這些文件中的每個文件都包含一個numpy數組,大小為10x5x50x50x3 我想創建一個5d numpy數組,其中將包含7000*10x5x50x50x3 我嘗試使用兩個for循環來這樣做。 我的示例代碼:

fnl_lst = []
for object in list_of_objects:
     my_array = read_array(object) # size 10x5x50x50x3
     for ind in my_array:
        fnl_lst.append(ind)
fnl_lst= np.asarray( fnl_lst) # print(fnl_lst) -> (70000,)

該代碼最終導致嵌套的numpy數組,其中包含70000個數組,每個數組的大小為5x50x50x3 但是,我想建立一個大小為70000x5x50x50x3的5d數組。 我該怎么做呢?

fnl_lst = np.stack([ind for ind in read_array(obj) for obj in list_of_objects])

或者,只需追加到現有代碼:

fnl_lst = np.stack(fnl_lst)

UPD:根據hpaulj的評論,如果my_array的確為10x5x50x50x3,則可能就足夠了:

fnl_lst = np.stack([read_array(obj) for obj in list_of_objects])

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM