# Understand elided index

**URL:** <https://forum.kx.com/t/understand-elided-index/7302>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [September 21, 2011, 7:11pm UTC](https://forum.kx.com/t/understand-elided-index/7302 "2011-09-21T19:11:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dbtouch](https://avatars.discourse-cdn.com/v4/letter/d/9de053/32.png) [@dbtouch](https://forum.kx.com/u/dbtouch)\
**Post date:** [September 21, 2011, 7:11pm UTC](https://forum.kx.com/t/understand-elided-index/7302/1 "2011-09-21T19:11:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![\_Oz](https://avatars.discourse-cdn.com/v4/letter/_/f07891/32.png) [@\_Oz](https://forum.kx.com/u/_Oz)\
**Post date:** [September 21, 2011, 7:42pm UTC](https://forum.kx.com/t/understand-elided-index/7302/2 "2011-09-21T19:42:00Z")

</div>

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

?

---

<div class="post-metadata">

**Author:** ![dbtouch](https://avatars.discourse-cdn.com/v4/letter/d/9de053/32.png) [@dbtouch](https://forum.kx.com/u/dbtouch)\
**Post date:** [September 22, 2011, 4:21pm UTC](https://forum.kx.com/t/understand-elided-index/7302/3 "2011-09-22T16:21:00Z")

</div>

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&gt;&gt](https://code.kx.com/trac/wiki/QforMortals2/contents&gt;&gt); 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…\>
