The core Problem: I have paths saved as a triple nested lists and I fail to index them properly.
Here is a minimal example
l1 = []
l11 = [[1], [1, 2], [1, 2, 3], [1, 2, 3, 4]]
l12 = [[5], [5, 6], [5, 6, 7], [5, 6, 7, 8]]
l1.append(l11)
l1.append(l12)
# Goal:
l_target = [[[1], [1, 2], [1, 2, 3]], [[5], [5, 6], [5, 6, 7]]]
print(l1[:][:4] == l_target)
Explaining the list in question: The first dimension is the number of paths. Each path is a list that represent the values at the different timesteps. Each timestep is a list, where every timestep has a different dimension, which is the reason I have a tripple nested list and not a matrix.
Since this is very confusing here is an example:
For this example my val paths are saved in h1 (usually multiple hundred, I reduced it to 2 for this example). I have expanded the first path and you can see that at time k it consists of all values up to time k.
The problem is that I want a single line code that remove all timesteps after k for all paths.
To me it seemed very simple as "[:][:k]" should do it, however it doesn't change the list at all (see h2 == h1). As stuff like [:, :k] doesn't work either I am quite confused.
l1[:]is just the same asl1. Sol1[:][:k]is the same asl1[:k], which just means take the first k lists in the first dimension. Note for example thatl1[:][:1]is[[[1], [1, 2], [1, 2, 3], [1, 2, 3, 4]]]. The array slice only considers the first dimension of arrays. You might find this question useful instead.[1, 2, 3, 4]and[5, 6, 7, 8]missing it l_target? They're the fourth elements inl11andl12.l11[:4]andl12[:4]both contain the entire lists.