DevLoverUmar
DevLoverUmar

Reputation: 13923

How to reshape a 3-D array to 2-D in python?

I'm working with a timeseries data pipeline. I created a list of sequences as sequences=list() Then I appended array items of the shape (30,201) on each iteration where 30 is the row count and 201 is my features length. Total items are around 2000. At the end I comnverted my list to array with

3Darray=np.stack(sequences) # I also tried np.array(sequences) as well

Now, my array has the shape(2000,30,201). I want to restore my original 2D features data with the shape (2000*30,201). But when I try

3Darray.resahpe(3Darray.shape[0]*3Darray.shape[1],201) 
3Darray.shape

No change in shape happens. What I'm doing wrong here?

I tried to follow this SO answer but I did succeed.

Upvotes: 0

Views: 62

Answers (1)

Andrea Di Iura
Andrea Di Iura

Reputation: 457

You should assign the result of 3Darray.resahpe(3Darray.shape[0]*3Darray.shape[1],201) to a new variable, see the documentation of reshape: This will be a new view object if possible; otherwise, it will be a copy. Note there is no guarantee of the memory layout (C- or Fortran- contiguous) of the returned array

Upvotes: 1

Related Questions