If I understand your situation correctly, pyplot.imshow() will know nothing about the individual image dimensions, as you have it right now. It will consider your matrix as pixel values for a single image, of dimensions 20 pixels by 400 pixels, because that is the shape of your matrix. For instance:
import numpy as np
import matplotlib.pyplot as plt
''' Create a matrix of random values, of shape (20,400)
I used random integer values here between 0 and 255
but you can do the same for decimal pixel intensities '''
mat = np.random.randint(0,255,400*20).reshape(20,400)
# Call imshow:
plt.imshow(mat, cmap='gray')
plt.show()
Gives you this image:

Since your 20x20 images are essentially stored in the second dimension of the matrix, you can show an individual image, in 20x20 format (you explicitly have to reshape it, though), as such:
plt.imshow(mat[0,:].reshape(20,20), cmap='gray')
plt.show()
This returns the 1st image:

For the second image, use mat[1,:].reshape(20,20), etc...
[EDIT]: To see how imshow() plots your images row by row, consider the following matrix in which pixel intensities are steadily decreasing:
example_mat = np.linspace(1,0, 25).reshape(5,5)
>>> example_mat
array([[ 1. , 0.95833333, 0.91666667, 0.875 , 0.83333333],
[ 0.79166667, 0.75 , 0.70833333, 0.66666667, 0.625 ],
[ 0.58333333, 0.54166667, 0.5 , 0.45833333, 0.41666667],
[ 0.375 , 0.33333333, 0.29166667, 0.25 , 0.20833333],
[ 0.16666667, 0.125 , 0.08333333, 0.04166667, 0. ]])
If you call imshow() on this matrix, you get this image:

As you can see, the first "row" of your matrix (example_mat[0,:]) is the first (i.e. top) "row" of your image.