Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
101 views
in Technique[技术] by (71.8m points)

python - Get a ValueError when converting an array of images into float

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...