Keras input shape returning an error I am currently learning about Keras and have a problem with the input shape of a dense layer.I am currently trying to the mnist dataset.I understand that the input_shape for the train images is (60000,28,28) also i understand that keras ignores the first dimension as it is the batch size hence the input shape entered in the dense model should be (28,28) but when putting that i get an error yet when i put input shape of(784,) the model runs.Could someone please explain why is that so

(train_images, train_labels), (test_images, test_labels) = 
 mnist.load_data()

 print(train_images.shape)


 network = models.Sequential()
 network.add(layers.Dense(512, activation='relu', input_shape=(28,28)))
 network.add(layers.Dense(10, activation='softmax'))
You always need to flatten your pictures when connecting the input to a Dense layer in Keras (Note that this is not the case for CNNs or RNNs). The reason is when the dense layer is built, based on the Dense layer code, the input dim is the last element you pass in the inputs (input_dim = input_shape[-1]). Therefore, although you are passing an input of (28,28) keras thinks that the shape is only 28. This also explains why the input of (,784) indeed works. 

You can check the Dense layer code here