Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reshape 4d array to 2d array in numpy

I have a 4d array of shape like this. It has total 18*100 = 1800 rows and 30 dimensional outputs per row

(18, 100, 30, 1, 1)

i want to convert or reshape this into 2d array, the easiest way

(1800,30)

Sorry for being so naive with numpy, but please i am a novice user. Any help much appreciated.

like image 726
pbu Avatar asked Jan 08 '23 23:01

pbu


2 Answers

numpy.reshape(input_in_4D, (1800,30))

Of course this just converts the input in the default order (meaning you "unroll" the input array from inner to outer); if you need special ordering, you should read up on slicing.

like image 160
Marcus Müller Avatar answered Jan 26 '23 18:01

Marcus Müller


You can use reshape method:

newArray = oldArray.reshape(1800,30)
like image 21
pyAddict Avatar answered Jan 26 '23 18:01

pyAddict