That’s strange, as it’s not working for me:
plt.imshow(np.random.randn(24, 24, 1))
> TypeError: Invalid shape (24, 24, 1) for image data

However, based in the stack trace, it seems that you are reshaping the image, so the error might be in some code part, which is not posted.