I have two numpy arrays:
Values = numpy.array([5, 6, 7, 8, 1, 2, 3, 14, 15, 16])
Lengths = numpy.array([4, 3, 3])
What would be an efficient way to in numpy to reverse the order within the sublist to get this?
[8, 7, 6, 5, 3, 2, 1, 16, 15, 14]
I have tried for loop, but I believe there should be a more efficient way to do it using numpy functions.
You can do this by splitting the array (using
np.split) at the desired indices, given bynp.cumsum(Lengths), and then concatenating (using np.concatenate) them after each is reversed.Output: