I get an array of 3 elements that are arrays of 10 elements each. Then If I call
a[2][:]
I get an array of length 10 which is normal and fine. But If I call
a[:][1]
I also get an array of length 10 when I expect to have an array of length 3 composed of the first element of each arrays stored in a.
In fact using “:” in one way (a[n][:]) or another (a[:][n]) always gives me back the same array.
Is this an expected behavior and I missed something or simply a bug ?
Note this is a single indexation passing : and 1 separated by a ,, not two indexations executed one after the other. If you have a Vector of Vectors then the outer vector does not know about the inner ones (nor there is guarantee the inner vectors have the same size), so the solution by @pdeffebach is the way to go.
Well there is an allocation/copy with a[:], but I don’t think that’s your issue here. With a[:], you are accessing all the elements of a. You will get the same result with view(a,:)[1] where view(a,:) is “just indexing”.