Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: How can I reshape 3D Images (np array) to 1D and then reshape them back correctly to 3D?

I have RGB images (32 x 32 x 3) saved as 3D numpy arrays which I use as input for my Neural Net (using tensorflow). In order to use them as an input I reshape them to a 1D np array (1 x 3072) using reshape(1,-1). When I finish training my Net I want to reshape the output back, but using reshape(32,32,3) doesn't seem to provide the desired outcome.

Is this the correct way to do it? How I can be sure that each datum will be back to the correct place?

like image 884
costisst Avatar asked Dec 24 '22 18:12

costisst


1 Answers

If you are looking to create a 1D array, use .reshape(-1), which will create a linear version of you array. If you the use .reshape(32,32,3), this will create an array of 32, 32-by-3, arrays, which is the original format described. Using '-1' creates a linear array of the same size as the number of elements in the combined, nested array.

like image 198
Benedict Bunting Avatar answered Dec 30 '22 20:12

Benedict Bunting