0

I need to read images (500x300x3) and store them in arrays:

import os
import numpy as np

data = np.empty((number_of_images, 3, 300, 500), dtype="float32")

imgs = os.listdir("./images")
num = len(imgs)
for i in range(num):
    img = Image.open("./images/" + imgs[i])
    arr = np.asarray(img, dtype="float32")
    data[i, :, :, :] = arr

now here error occurs because the size of arr is 500x300x3, but I want to store it as np.empty((number_of_images, 3, 300, 500), dtype="float32").

Any suggestions will be greatly appreciated!

1 Answer 1

1

Transpose the array:

data[i, :, :, :] = arr.transpose(2, 1, 0)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.