I am trying to extract part of an array from an array.
Let's assume I have an array array1
with shape (M, N, P)
. For my specific case, M = 10
, N = 5
, P = 2000
. I have another array, array2
of shape (M, N, 1)
, which contains the starting points of the interesting data in array1
along the last axis. I want to extract 50 points of this data starting with the indices given by array2
, kind of like this:
array1[:, :, array2:array2 + 50]
I would expect a result of shape (M, N, 50)
. Unfortunatly I get the Error:
TypeError: only integer scalar arrays can be converted to a scalar index
Sure I could also get the result by looping through the array, but I feel that there must be a smarter way, because I needed this quite often.