2

I have a NumPy array called FLAIR_X with 583 images. Each image can be extracted by using the index (e.g., plt.imshow(FLAIR_X[0])). Currently, the shape of the array is (583,), but sklearn needs an array of size (583, 224, 224) ((224,224)being the size of a single image). This will also make it easier to work with. I tried doing :

temp = FLAIR_X.reshape(583, 224, 224)

But I got the error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-108-4bb1899edbd8> in <module>
----> 1 temp = FLAIR_X.reshape(583, 224, 224)

ValueError: cannot reshape array of size 583 into shape (583,224,224)

How can I reshape this array, so that is meets the requirements?

P.S: Just an extra question, will I be able to display images like earlier (plt.imshow(FLAIR_X[0])) after I reshape the data?

Thanks,

2
  • What is the type of your image? Commented Aug 8, 2021 at 18:54
  • It is a NumPy array with shape (224, 224). Commented Aug 8, 2021 at 18:55

1 Answer 1

1

Have you tried simply calling:

res = np.array(FLAIR_X)

If that does not help, try:

l = FLAIR_X.tolist()
res = np.array(l)

If that does not help either, I don't believe your elements are numpy arrays.

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.