I want to slice out parts of my array foo
multiple times. Currently I am using a for loop which I want to substitute through matrix computation to get a better performance in terms of speed.
foo = np.arange(6000).reshape(6,10,10,10)
target = np.zeros((100,6,3,4,5))
startIndices = np.random.randint(5, size=(100))
This is my current approach.
for i in range(len(target)):
startIdx=startIndices[i]
target[i, :]=foo[:, startIdx:startIdx+3,
startIdx:startIdx+4,
startIdx:startIdx+5]
I tried to represent the slices as arrays, but I couldn't find the proper representation.