https://learninghub.kx.com/forums/topic/high-dimensional-matrix-index
apologies if this is obvious for Q professionals, I'm struggling to understand why running below in console returns 1 2 3 4 5 6, not 5 6 ? even ChatGPT says it returns 5 6...
mm:((1 2;3 4;5 6);(10 20;30 40;50 60))
mm 0 2
When indexing at depth you need the square brackets or index-at for nested indexing dot-apply
mm:((1 2;3 4;5 6);(10 20;30 40;50 60))
mm 0 2
1 2 3 4 5 6
0N!mm 0 2
((1 2;3 4;5 6);(long$();
long$();`long$()))
1 2 3 4 5 6
mm[0;2]
5 6
mm . (0;2)
5 6
mm . 0 2
5 6 If you really wanted you could use simple apply and the iterator over to achieve what you are looking for
mm@/0 2
5 6
If you use 0N! you can see that when using mm 0 2 you’re basically indexing at the first level, first for index 0 which returns the first top level, then at index 2 which doesn’t exist hence you get a list of empty long lists3. Lists - Q for Mortals Apply (At), Index (At), Trap (At) | Reference | kdb+ and q documentation - kdb+ and q documentation
mwoods
February 6, 2025, 1:11pm
3
To return 5 6 you will need to index at depth by passing a semicolon
mm[0;2]
5 6 Indexing by passing a list of integers returns all indexes so in this case:
mm 0 // returns the element at position 0
1 2
3 4
5 6 mm 2 // returns the element at position 2 - which doesn't exist
mm 0 2 // get both elements at positions 0 and 2 - because none at 2 we just get the 0 elements back
1 2 3 4 5 6
This concept covered in the free academy course in the module on List Amendment and eliding at depth.
https://learninghub.kx.com/courses/kdb-developer-level-2/lessons/lists/topic/list-indexing-access/
Thanks! good point to know!
Thanks! maybe time to refresh my memory of the course did some time ago...