Keras
error handling
machine learning
deep learning
troubleshooting

Keras error Expected to see 1 array

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

When training a Keras model, you may encounter the error "Expected to see 1 array(s), but instead got the following list of N arrays." This error occurs when the data you pass to model.fit() does not match what the model's input layer expects. Understanding why Keras raises this error and how to fix it will save you significant debugging time.

What the Error Means

Keras models define a fixed number of input tensors. A simple Sequential model with a single Dense input layer expects exactly one NumPy array (or one tensor). The error fires when you accidentally pass a list of multiple arrays, a tuple, or a data structure that Keras cannot interpret as a single input.

For example, this code triggers the error:

python
1from keras.models import Sequential
2from keras.layers import Dense
3import numpy as np
4
5model = Sequential([
6    Dense(64, activation='relu', input_shape=(10,)),
7    Dense(1, activation='sigmoid')
8])
9model.compile(optimizer='adam', loss='binary_crossentropy')
10
11# Wrong: passing a list of two arrays
12X_train = [np.random.rand(100, 5), np.random.rand(100, 5)]
13y_train = np.random.randint(0, 2, 100)
14
15model.fit(X_train, y_train, epochs=5)

Keras sees a list of two arrays but expects a single array with shape (samples, 10).

Root Causes

1. Splitting Features Incorrectly

A common mistake is splitting your features into separate arrays before training. If your model has one input, you need to concatenate them:

python
1# Wrong: two separate arrays
2X_part1 = np.random.rand(100, 5)
3X_part2 = np.random.rand(100, 5)
4X_train = [X_part1, X_part2]  # This is a list of 2 arrays
5
6# Correct: concatenate into one array
7X_train = np.concatenate([X_part1, X_part2], axis=1)  # Shape: (100, 10)
8model.fit(X_train, y_train, epochs=5)

2. Wrong Data Type or Structure

Pandas DataFrames, Python lists of lists, and other structures can cause unexpected behavior. Always convert your input to a NumPy array explicitly:

python
1import pandas as pd
2
3df = pd.DataFrame(np.random.rand(100, 10))
4X_train = df.values  # Convert to NumPy array with shape (100, 10)
5model.fit(X_train, y_train, epochs=5)

3. Mismatched Input Shape

If you define input_shape=(10,) but pass data with a different number of features, Keras may produce confusing errors. Always verify your shapes before calling fit():

python
print(X_train.shape)  # Should print (num_samples, 10)
print(y_train.shape)  # Should print (num_samples,) or (num_samples, 1)

4. Multi-Input Models Without Proper Wrapping

If you intentionally built a multi-input model using the Functional API, you need to pass inputs as a list — but the list length must match the number of Input layers:

python
1from keras.layers import Input, Dense, concatenate
2from keras.models import Model
3
4input_a = Input(shape=(5,))
5input_b = Input(shape=(5,))
6merged = concatenate([input_a, input_b])
7output = Dense(1, activation='sigmoid')(merged)
8model = Model(inputs=[input_a, input_b], outputs=output)
9model.compile(optimizer='adam', loss='binary_crossentropy')
10
11# Correct: pass a list matching the two Input layers
12model.fit([X_part1, X_part2], y_train, epochs=5)

Debugging Checklist

When you hit this error, follow these steps in order:

  1. Print type(X_train) and X_train.shape — confirm it is a single NumPy array with the expected dimensions.
  2. Check model.summary() — verify the input layer shape matches your data.
  3. Look at data preprocessing — ensure no step accidentally splits your data into a list.
  4. Confirm the model architecture — a Sequential model expects one input; a Functional API model with multiple Input layers expects a list.
python
model.summary()
# Look at the first layer's "Output Shape" to confirm expected input

Common Pitfalls

  • Passing a Python list instead of a NumPy array: A plain list like [array1, array2] is interpreted as multiple inputs, not as a single 2D array. Use np.array() or np.concatenate().
  • Forgetting to call .values on a DataFrame: Keras can misinterpret a Pandas DataFrame. Always convert to a NumPy array with df.values or df.to_numpy().
  • Reshaping errors with image data: For CNNs expecting 4D input (samples, height, width, channels), passing a 3D array triggers shape mismatches. Use np.expand_dims() to add the channel dimension.
  • Using train_test_split incorrectly: If train_test_split returns unexpected structures (for example, when applied to a list of arrays), the resulting splits may not be single arrays.
  • Mixing up Sequential and Functional API expectations: A Sequential model always takes one input. If you need multiple inputs, switch to the Functional API and pass a list of arrays whose length matches the number of Input layers.

Summary

  • The "Expected to see 1 array" error means Keras received multiple arrays when the model expects a single input.
  • Always verify your input data is a single NumPy array with the correct shape before calling model.fit().
  • Use np.concatenate() to merge separate feature arrays into one, or switch to the Functional API for true multi-input models.
  • Print X_train.shape and model.summary() as your first debugging step — shape mismatches cause the majority of Keras input errors.
  • Convert Pandas DataFrames to NumPy arrays explicitly to avoid ambiguous data structures.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

All Rights Reserved.