how to reshape xtrain array and what about input shape?
Keras requires you to set the input_shape of the network. This is the shape of a single instance of your data which would be (28,28). However, Keras also needs a channel dimension thus the input shape for the MNIST dataset would be (28,28,1).



First we load the data as you did,

from keras.datasets import mnist
import numpy as np

(x_train, y_train), (x_test, y_test) = mnist.load_data()

print('Training data shape: ', x_train.shape)
print('Testing data shape : ', x_test.shape)



  Training data shape:  (60000, 28, 28) 
  Testing data shape :  (10000, 28, 28)


Then we reshape the examples in the MNIST dataset to have the additional channel dimension

# Input image dimensions
img_rows, img_cols = 28, 28

# Channels go last for TensorFlow backend
x_train_reshaped = x_train.reshape(x_train.shape[0], img_rows, img_cols, 1)
x_test_reshaped = x_test.reshape(x_test.shape[0], img_rows, img_cols, 1)
input_shape = (img_rows, img_cols, 1)


And now we can define our model as you did. Do note the necessary Flatten layer between the Convolutional layers and the Dense layer.

model = Sequential()
model.add(Conv2D(32, kernel_size=(3, 3),
                 activation='relu',
                 input_shape=input_shape))
model.add(Conv2D(64, (3, 3), activation='relu'))
model.add(Flatten())
model.add(Dense(128, activation='relu'))
model.add(Dense(num_classes, activation='softmax'))

model.compile(loss=keras.losses.categorical_crossentropy,
              optimizer=keras.optimizers.Adadelta(),
              metrics=['accuracy'])

model.fit(xtrain, ytrain, epochs=10, batch_size=60000)