Why are we using expand dims

img_path = '/Users/parthsharma/Desktop/Machine Learning/Deep Learning/CNN/Data Generators/images/dogs/dog.19.jpg'
img = image.load_img(img_path, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)

what is the use of x = np.expand_dims(x, axis=0) above

hey @Par1hsharma ,
the reason being the input format of preprocess function , it wants the data to be processed provided as an array of image values. Hence we need to do it in that way accordingly.

x = image.img_to_array(img)
we have converted it to array but why expand dims

the reason to perform expand dims, is the nature on input that our model needs.
You might have seen in keras models we need to provide a parameter as batch_size, because our model needs data in batches.
Hence , to predict also , we need to pass a batch , hence we do so.