1

I have a multidimensional array, say:

x = np.random.randn(2,3,4,4)
x.shape
(2, 3, 4, 4)

Then I have an array, which contains a chosen index in the second dimension for all elements, say:

y = np.random.randint(3, size=2*4*4).reshape(2,4,4)
y.shape
(2, 4, 4)

I want to get an output array that contains all elements of x, apart from the second dimension, where it would have just one value specified by an index in y. So, the output array z would also have the shape of (2, 4, 4). How can I accomplish this using indexing? I've already tried all combinations of indexing with ellipsis and y, and moving around the dimensions of x.

jmich
  • 51
  • 5

0 Answers0