我有一個 NumPy 多維形狀陣列(1,76,76,255)。我想將它重塑為另一個多維形狀陣列(1,255,76,76)。它仍然是一個 4D 陣列,但我需要更改我猜的資料索引。
有沒有不使用回圈的簡單方法?
uj5u.com熱心網友回復:
您正在尋找的功能是np.moveaxis()讓您將源軸移動到其目的地。
>>> arr = np.random.random((1,76,76,255))
>>>
>>> arr.shape
(1, 76, 76, 255)
>>> arr2 = np.moveaxis(arr, 3, 1)
>>> arr2.shape
(1, 255, 76, 76)
>>>
請注意,這些軸是 0 索引的
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/445441.html
標籤:Python 数组 python-3.x 麻木的 numpy-ndarray
下一篇:我的PyAutoGUI腳本引發TypeError:'NoneType'objectisnotsubscriptableaftercalllocateOnScreen()
