Say that I have an array of arrays
array = np.random.randint(0, 6, (4, 6))
array
array([[3, 5, 2, 5, 1, 3],
[5, 3, 0, 1, 4, 3],
[2, 1, 0, 2, 2, 4],
[2, 1, 0, 4, 2, 2]])
And I also have arrays for desired start and end indices for slicing out this array for each row
starts = np.random.randint(0, 3, (4,))
ends = starts + 3
ends
array([6, 3, 4, 3])
How do I slice out the array of arrays using these indices?
For the example, the desired result will be
array([[5, 1, 3],
[5, 3, 0],
[1, 0, 2],
[2, 1, 0]])
something like array[starts:ends] does not work
[5,6,7, 3,4,5, 4,5,6, 3,4,5]array([6, 3, 4, 3])orarray([5, 2, 3, 2]), but the former is impossible withnp.random.randint(0, 3, (4,))and the later impossible withends = starts + 3. So I expect the desired result not to be possible with the provided information: the first line should be2, 5, 1.