I was experimenting with different shapes of input array to the Keras sequential layer and the input_dim property. Like below:

X_train = np.array([0., 1, 2, 3, 4, 5])

print(X_train.shape)

X_train_reshap = X_train.reshape(-1,1)

print(X_train_reshap.shape)

model = Sequential(

[

tf.keras.layers.Dense(1, input_dim=1, activation = ‘sigmoid’, name=‘L1’)

]

)

layer = model.get_layer(‘L1’)

model.summary()

a1 = model.predict(X_train_reshap)

print(a1)

Here even though the value for *input_dim* is 1. the model is working for both **X_train** & **X_train_reshap**.

The shape of **X_train** is (6,) which is a 1D array as it is a flat array and the shape of **X_train_reshap** is (6, 1) which is a 2D array as it has 2 dimensions i.e. 6 Rows & 1 Column. How it’s working? though it’s emitting different results for *a1*.

As per my understanding the *input_dim* should have been 2 if I am using **X_train_reshap** as input but when I am doing that I am having the below error:

**Input 0 of layer “L1” is incompatible with the layer: expected axis -1 of input shape to have value 2, but received input with shape (None, 1)** .

So I believe I my understanding is not right either about 1D & 2D array or about the input_dim argument in the keras API.

Can anyone please explain?