Hi, KDB FolksI am having difficulty understanding elided index example in qlanguage 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
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 ;-))
https://code.kx.com/trac/wiki/QforMortals2/contents
Free to read from kx site.
Please, consider reading it - lots of fun & time well invested.
Cheers,
Oleg
?
That is awesome. Thanks, Oleg.On Sep 21, 2:42?pm, Oleg Zakharov <zakharovo…> wrote:> 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> ;-))https://code.kx.com/trac/wiki/QforMortals2/contents>> Free to read from kx site.> Please, consider reading it - lots of fun & time well invested.>> Cheers,> Oleg>>>>>>>> On Wed, Sep 21, 2011 at 10:11 PM, dbtouch <dbto…> wrote:> > 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>> > –> >
Submitted via Google Groups</dbto…></zakharovo…>