Change image channel ordering from channel first to last

I want to change the ordering of this numpy images array to 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) to (301, 350, 350, 1)

I tried this but it is not working

np.rollaxis(training_data,0,3).shape
np.rollaxis(validation_data,0,3).shape
np.rollaxis(testing_data,0,3).shape

Answer

You need the np.transpose method like this:

training_data = np.transpose(training_data, (0, 2,3,1)

The same for the other ones