0

I have a dataset which comprises of the binary data of pixelated 50x50 images. The array shape is (50, 50, 90245). I want to reach 50x50 pixels of each of the 90245 images. How can I slice the array?

5
  • What would be the shape of your expected output array? Commented Mar 19, 2022 at 20:52
  • I suppose it should be (50x50) for every 90245 Commented Mar 19, 2022 at 20:53
  • So basically you have 90245 images that are each 50x50, and you want to get them all into a list? So maybe you want to change the shape to (90245, 50, 50) Commented Mar 19, 2022 at 20:55
  • 1
    Actually, the proposed solution in the answer worked for me. When I tried your way, it gave me different data Commented Mar 19, 2022 at 21:03
  • 1
    I think you should read the numpy manual on indexing Commented Mar 19, 2022 at 21:07

2 Answers 2

1

If data is the variable storing the image data, and i is the index of the image you want to access, then you can do:

data[:,:,i]

to get the desired image data.

Sign up to request clarification or add additional context in comments.

Comments

0

If data is the variable storing the image data, and i is the index of the image you want to access, then you can do as @BrokenBenchmark suggested. In case you want a (50,50,1) 3D array as the output, you could do:

data[:,:,i:i+1]

to get the image as a 3D array.

Edit1: If you reshaped your data matrix to be of shape (90245,50,50), you can get the ith image by doing data[i,:,:] or just data[i] to get a (50,50) image. Similarly, to get a (1,50,50) image, you could do data[i:i+1,:,:] or just data[i:i+1].

Edit2: To reshape the array, you could use the swapaxes() function in numpy.

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.