ValueError: cannot reshape array of size 74404 into shape (6764,1691,1)

My df shape is 2D (6764, 11).

I want to reshape it into 3D with 1691 time steps (i.e., 1/4 of 6764)

df = df.values.reshape((df.shape[0], 1691, df.shape[1]))

I get the error: ValueError: cannot reshape array of size 74404 into shape (6764,1691,11)

Why I get size 74404??? I get is 1674*11, but why is doing this multiplication?

edit

I actually want to reshape my data into [6764, 1691, 11], which is the dimension required for an LSTM model. This dimension stands for [Samples, TimeSteps, Features] where samples are the number of data points, time steps the number of data points I want to analyse/predict, and 11 the inputs (columns) I am using. Any advise on how to achieve this shape without getting the error ? my reference is this

1 answer

  • answered 2020-07-29 17:51 pgg08927

    From 2D dataframe you have an array of 6764 x 11 = 74404 values.

    Multiplication indicates the number of values you have in the array/dataframe.

    from your code (df.shape[0], 1691, df10.shape[1])) it would generate 6764 x 1691x 11 = 125817164 which is not matching to input array values thats why you are getting an error.

    Considering you want 1691 series you can reshape your data into (1691 x 4 x 11)

    df = df.values.reshape((1691,4, df.shape[1]))
    

    If you need only 1st column that is 6764 values to reshape then use below code although it will generate 2D array with (1691,4) shape.

    df = df['column_name'].values.reshape((1691,4))