There are various methods to do that:
You can simply use numpy.rollaxis to move the axis 3 to position 1
np.rollaxis(imagesArray, 3, 1)
When using keras, you might want to change its configuration. But Theano library doesn't need anything if Keras is being used.
Keras can be configured with channels first or channels last, besides allowing you to define it in every individual layer, so you don't have to change your data.
To configure keras
You should find the keras.json file, then change it. The file is usually installed in
depending on your OS.
You should change "image_data_format": "channels_last" to "channels_first" or vice-versa
When working with "channels_last" is less troublesome because of a great number of other functions that work only on the last axis.