Rearranging a 4d numpy array

后端 未结 2 871
暖寄归人
暖寄归人 2020-12-22 02:15

I have a 4d numpy array which represents a dataset with 3d instances. Lets say that the shape of the array is (32, 32, 3, 73257).

How can i change the

2条回答
  •  猫巷女王i
    2020-12-22 02:42

    It looks like np.rollaxis(arr, axis=-1) will do what you want. Example:

    >>> arr = np.empty(32, 32, 3, 73257)
    >>> arr2 = np.rollaxis(arr, axis=-1)
    >>> arr2.shape
    (73257, 32, 32, 3)
    

    This will make arr[i,j,k,l] == arr2[l,i,j,k] for all ijkl

提交回复
热议问题