Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reshape numpy image? [duplicate]

I have an image as a numpy array with shape (channels, height, width) how can I reshape it so that it has shape (height, width, channels)?

like image 638
Aly Avatar asked May 20 '15 10:05

Aly


2 Answers

I assume it would be quicker to use the built-in numpy function.

np.rollaxis(array_name,0,3).shape
like image 121
Rob Avatar answered Sep 20 '22 14:09

Rob


You can use transpose() to choose the order of the axes. In this case you want:

array.transpose(1, 2, 0)

This creates a new view onto the original array whenever possible (no data will be copied).

like image 21
Alex Riley Avatar answered Sep 18 '22 14:09

Alex Riley