0

I am attempting to index a stacked 3-D Numpy array (named stack) by a group of 2-D indices contained inside of a separate Numpy array (named piece). The separate array contains several groups of 2-D index pairs. Inspection of these indices at the first entry of the array is as follows:

[[0 1]
 [1 0]
 [0 0]
 [1 1]
 [2 0]
 [0 2]
 [2 1]
 [1 2]]

The dimensions of the stacked 3-D array are (1228, 2606, 14), which was created by stacking multiple 2-D arrays to ultimately inspect values along common index value pairs. I've tried indexing stack by piece in several methods, both of which have not produced the desired result:

  1. extraction = stack[tuple(piece), :]
  2. extraction = stack[piece, :]

Attempt #1 was derived from this question here. In both instances, the shape of extraction yields (8, 2, 2606, 14) as opposed to an array that contains 112 values across the 8 provided index pairs. Any insight as to where corrections can be made is appreciated!

2
  • 1
    stack[piece[:,0], piece[:,1]]? Commented Apr 4, 2023 at 15:49
  • That would do it, thanks! Commented Apr 4, 2023 at 16:46

0

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.