-2

I have 3D array with (1000, 256, 256) shape. I want to take away the 100-200th entry from the x dimension (with 1000 items). Writing [0:100, 101:1001] makes the cut from the second dimension (with 256 items).

How do I index it?

dududiary
  • 3
  • 1
  • 1
    Does this answer your question? [How to crop an image in OpenCV using Python](https://stackoverflow.com/questions/3877491/deleting-rows-in-numpy-array) – JE_Muc Dec 08 '20 at 11:08
  • I accidentally clicked the wrong link for the duplicate. The correct link and description should be: [deleting rows in numpy array](https://stackoverflow.com/questions/3877491/deleting-rows-in-numpy-array) – JE_Muc Dec 08 '20 at 11:16

1 Answers1

1

You have two options. Either slice two times and concatenate manually:

arr = np.random.rand(1000, 256, 256)

arr2 = np.vstack((arr[:100], arr[200:]))

Or use np.delete:

arr3 = np.delete(arr, slice(100, 200), axis=0)

Both results are equal:

np.all(arr2 == arr3)
# Out: True
JE_Muc
  • 5,403
  • 2
  • 26
  • 41