title: Problem in reshaping train and validation data for 1D CNN
body: <p>I want to train 1D CNN on physioNet2017 ECG data. Each row in training data is of valiable length i.e, some rows are 9000 columns long and some are 18286 columns long. To make them of same length i have padded zeros to each row upto maximum length that 18286.
  Now i have 20200 rows and each row is 18286 columns long so data shape is (20200, 18286). now i want to reshape this data in order to train 1D CNN. i have used following code for splitting the data into training and validation.</p>
  <pre><code>Xt, Xv, Yt, Yv = train_test_split(trainX_bal, trainY_bal, random_state=42, test_size=0.2)
  print(&quot;Train shape: &quot;, Xt.shape)
  print(&quot;Valdation shape: &quot;, Xv.shape)
  </code></pre>
  <p>and i have output:
  Train shape:  (16160, 18286)
  Valdation shape:  (4040, 18286)</p>
  <p>Now i have reshaped the training and validation data using following code:</p>
  <pre><code>samples_train = list()
  samples_val = list()
  samples_test = list()
  length = 8
  for i in range(0,Xt.shape[0],length):
   sample = Xt[i:i+length]
   samples_train.append(sample)
  for i in range(0,Xv.shape[0],length):
   sample_val = Xv[i:i+length]
   samples_val.append(sample_val)
  
  data = np.array(samples_train).astype(np.float32)
  data_val = np.array(samples_val).astype(np.float32)
  
  print(&quot;Training new shape: &quot;, data.shape)
  print(&quot;Validation new shape: &quot;, data_val.shape)
  
  Xt_cnn = data.reshape((len(samples_train), length, data.shape[2]))
  Xv_cnn = data_val.reshape((len(samples_val), length, data_val.shape[2]))
  
  Yt = to_categorical(Yt, num_classes=4)
  Yv = to_categorical(Yv, num_classes=4)
  </code></pre>
  <p>the output is:
  Training new shape:  (2020, 8, 18286)
  Validation new shape:  (505, 8, 18286)</p>
  <p>Now i fit this data to CNN model using following code:</p>
  <pre><code>mod = cnn_model(Xt_cnn)
  cnn_history = mod.fit(Xt_cnn, Yt, batch_size=64, validation_data = (Xv_cnn, Yv), 
                         epochs=20)
  </code></pre>
  <p>i get this error.
  <a href="https://i.stack.imgur.com/WReml.png" rel="nofollow noreferrer">Error</a></p>