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?
question from:
https://stackoverflow.com/questions/65932677/get-a-valueerror-when-converting-an-array-of-images-into-float 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…