我有一部電影,從一個 tif 文件加載skimage.external.tifffile.imread()到一個形狀為 的 numpy 數組中(frames, width, height)。將電影重新排序為形狀的最佳方法是( width, height, frames)什么?我可以構建一個使用 for 循環(huán)執(zhí)行此操作的函數,但是有沒有更好的方法可以在避免 for 循環(huán)實現的同時重塑?問題的某種矢量化?
2 回答

臨摹微笑
TA貢獻1982條經驗 獲得超2個贊
您可以先進行轉置,然后再進行交換軸:
import numpy as np
movies = np.zeros((10, 250, 100))
print(movies.shape)
print(np.swapaxes(movies.T, 0, 1).shape)
輸出
(10, 250, 100)
(250, 100, 10)
添加回答
舉報
0/150
提交
取消