将图像通道顺序从第一个通道更改为最后一个

Ous*_*ama 2 python numpy

我想将这个 numpy 图像数组的顺序更改为 channel_last training_data : (2387, 1, 350, 350) to (2387,350,350,1) validation_data : (298, 1, 350, 350) to (298, 350, 350) , 1) testing_data : (301, 1, 350, 350) 到 (301, 350, 350, 1)

我试过这个,但它不起作用

np.rollaxis(training_data,0,3).shape
np.rollaxis(validation_data,0,3).shape
np.rollaxis(testing_data,0,3).shape
Run Code Online (Sandbox Code Playgroud)

Fly*_*ler 8

你需要这样的np.transpose方法:

training_data = np.transpose(training_data, (0, 2,3,1)
Run Code Online (Sandbox Code Playgroud)

其他的也一样