Understand elided index

98 views
Skip to first unread message

dbtouch

unread,
Sep 21, 2011, 2:11:12 PM9/21/11
to Kdb+ Personal Developers
Hi, KDB Folks

I am having difficulty understanding elided index example in q
language reference manual:

d:((1 2 3;4 5 6 7);(8 9;10;11 12);(13 14;15 16 17 18;19 20))

what is the straight forward way to evaluate d[0 2;;1 0]?

Thanks

Oleg Zakharov

unread,
Sep 21, 2011, 2:42:08 PM9/21/11
to personal...@googlegroups.com
Meaning what exactly?
You can think of it as a projecting 3-dim array, you're projecting it to 4 lines
To comprehend better what will happen here, do it in steps
you have d (unfortunately console isn't 3d ;-))
So, you'll have elements listed vertically by top (leftmost) index. Upper is 0th 

q)d
(1 2 3;4 5 6 7)
(8 9;10;11 12)
(13 14;15 16 17 18;19 20)

d[0;;] (leaving only 0th element - flattening 3-dim to 2-dim, along 0 as a 1st index) 
q)d[0;;]
1 2 3
4 5 6 7

((1 2 3;4 5 6 7) that is)

d[0 2;;] (leave only 0th and 2nd elements toplevel-wise)

q)d[0 2;;]
(1 2 3;4 5 6 7)
(13 14;15 16 17 18;19 20)

Then, you are projecting this result further, now from the deep end
q)d[0 2;;][;;0]
1 4
13 15 19

meaning, that from the each of the 3rd level lists you want to keep only 0th element

or, as original design was, you want to leave 2 elements, 1st and 0th (in this order, reverse to original) 
q)d[0 2;;][;;1 0]
(2 1;5 4)
(14 13;16 15;20 19)

That's it. Compact notation is not affecting the result.
 q)d[0 2;;1 0]
(2 1;5 4)
(14 13;16 15;20 19)

As a side note - there's a great book on Q (best ever - as it's the only one ;-))

Free to read from kx site.
Please, consider reading it - lots of fun & time well invested.

Cheers,
Oleg
 


--
You received this message because you are subscribed to the Google Groups "Kdb+ Personal Developers" group.
To post to this group, send email to personal...@googlegroups.com.
To unsubscribe from this group, send email to personal-kdbpl...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/personal-kdbplus?hl=en.


dbtouch

unread,
Sep 22, 2011, 11:21:43 AM9/22/11
to Kdb+ Personal Developers
That is awesome. Thanks, Oleg.
> ;-))https://code.kx.com/trac/wiki/QforMortals2/contents
Reply all
Reply to author
Forward
0 new messages