I have a list of images of various dimensions:
images = []
for direct in directory:
img = cv2.imread(direct)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
images.append(img)
I intend to normalise the images therefore I should first convert the array images into float by x = np.asarray(images).astype(np.float32)
, but I get the following error:
TypeError Traceback (most recent call last)
TypeError: only size-1 arrays can be converted to Python scalars
The above exception was the direct cause of the following exception:
ValueError Traceback (most recent call last)
<ipython-input-33-6b9623418638> in <module>
----> 1 x = np.asarray(images).astype(np.float32)
ValueError: setting an array element with a sequence.
The error corresponds to the astype(np.float32)
, how do I fix it?