0

Not sure the title is correct, but I have an array with shape (84,84,3) and I need to get subset of this array with shape (84,84), excluding that third dimension.

How can I accomplish this with Python?

Edy Bourne
  • 5,679
  • 13
  • 53
  • 101
  • What do you mean 'excluding that third dimension'? You need to specify exactly which subset you want. If you are using `numpy` for example, this would be very easy. – mapf May 25 '20 at 08:04

2 Answers2

2
your_array[:,:,0]

This is called slicing. This particular example gets the first 'layer' of the array. This assumes your subshape is a single layer.

Simon Notley
  • 2,070
  • 3
  • 12
  • 18
1

If you are using numpy arrays, using slices would be a standard way of doing it:

import numpy as np

n = 3  # or any other positive integer
a = np.empty((84, 84, n))

i = 0  # i in [0, n]
b = a[:, :, i]

print(b.shape)

I recommend you have a look at this.

mapf
  • 1,906
  • 1
  • 14
  • 40