python数组array的transpose方法

import cv2
import imageio
import matplotlib.pyplot as plt
import numpy as npif __name__ == '__main__':
    temp0 = np.array([[[[0.], [1.]], [[0.], [1.]], [[0.], [1.]], [[0.], [1.]]],
                      [[[0.], [1.]], [[0.], [1.]], [[0.], [1.]], [[0.], [1.]]],
                      [[[0.], [1.]], [[0.], [1.]], [[0.], [1.]], [[0.], [1.]]],
                      [[[0.], [1.]], [[0.], [1.]], [[0.], [1.]], [[0.], [1.]]]])
    temp1 = temp0.transpose(2, 0, 1, 3)
    temp2 = np.array([[[[0.], [0.], [0.], [0.]],
                      [[0.], [0.], [0.], [0.]],
                      [[0.], [0.], [0.], [0.]],
                      [[0.], [0.], [0.], [0.]]],
                     [[[1.], [1.], [1.], [1.]],
                      [[1.], [1.], [1.], [1.]],
                      [[1.], [1.], [1.], [1.]],
                      [[1.], [1.], [1.], [1.]]]])
    print((temp1 == temp2).all())
    print(temp0.shape)
    print(temp1.shape)
    print(temp2.shape)
原文地址:https://www.cnblogs.com/iuyy/p/14058184.html