Suppose I have a numpy array like this:
arr = np.array([[1,1,1,1], [2,2,2,2], [3,3,3,3], [4,4,4,4])
I also have a list that determines the intended lengths:
lens = [1,2,3,4]
Is there an elegant and Pythonic way to return a new array, with each corresponding element selected using the lens variable?
The output should be:
[[1], [2,2],[3,3,3], [4,4,4,4]]