Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change image channel ordering from channel first to last

Tags:

python

numpy

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
like image 482
Oussama Avatar asked Oct 17 '25 20:10

Oussama


1 Answers

You need the np.transpose method like this:

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

The same can be done for the other ones

like image 79
FlyingTeller Avatar answered Oct 20 '25 08:10

FlyingTeller



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!