# high dimensional matrix index

**URL:** <https://forum.kx.com/t/high-dimensional-matrix-index/14135>\
**Category:** Community Support\
**Tags:** imported, kdb-and-q\
**Created:** [February 6, 2025, 12:58pm UTC](https://forum.kx.com/t/high-dimensional-matrix-index/14135 "2025-02-06T12:58:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lestat-jin](https://sea2.discourse-cdn.com/flex002/user_avatar/forum.kx.com/lestat-jin/32/128_2.png) [@lestat-jin](https://forum.kx.com/u/lestat-jin)\
**Post date:** [February 6, 2025, 12:58pm UTC](https://forum.kx.com/t/high-dimensional-matrix-index/14135/1 "2025-02-06T12:58:47Z")

</div>

[https://learninghub.kx.com/forums/topic/high-dimensional-matrix-index](https://learninghub.kx.com/forums/topic/high-dimensional-matrix-index)

apologies if this is obvious for&nbsp; Q professionals, I'm struggling to understand why running below in console returns 1 2 3 4 5 6,&nbsp; not 5 6&nbsp; ?&nbsp; even ChatGPT says it returns 5 6...

mm:((1 2;3 4;5 6);(10 20;30 40;50 60))

mm 0 2

---

<div class="post-metadata">

**Author:** ![unterrainer\_ale](https://sea2.discourse-cdn.com/flex002/user_avatar/forum.kx.com/unterrainer_ale/32/108_2.png) [@unterrainer\_ale](https://forum.kx.com/u/unterrainer_ale)\
**Post date:** [February 6, 2025, 1:06pm UTC](https://forum.kx.com/t/high-dimensional-matrix-index/14135/2 "2025-02-06T13:06:21Z")

</div>

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 lists  
[3. Lists - Q for Mortals](https://code.kx.com/q4m3/3_Lists/#382-indexing-at-depth)  
[Apply (At), Index (At), Trap (At) | Reference | kdb+ and q documentation - kdb+ and q documentation](https://code.kx.com/q/ref/apply/#apply-index)

---

<div class="post-metadata">

**Author:** ![mwoods](https://sea2.discourse-cdn.com/flex002/user_avatar/forum.kx.com/mwoods/32/35_2.png) [@mwoods](https://forum.kx.com/u/mwoods)\
**Post date:** [February 6, 2025, 1:11pm UTC](https://forum.kx.com/t/high-dimensional-matrix-index/14135/3 "2025-02-06T13:11:22Z")

</div>

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/

---

<div class="post-metadata">

**Author:** ![lestat-jin](https://sea2.discourse-cdn.com/flex002/user_avatar/forum.kx.com/lestat-jin/32/128_2.png) [@lestat-jin](https://forum.kx.com/u/lestat-jin)\
**Post date:** [February 9, 2025, 5:02pm UTC](https://forum.kx.com/t/high-dimensional-matrix-index/14135/4 "2025-02-09T17:02:34Z")

</div>

Thanks!&nbsp; good point to know!

---

<div class="post-metadata">

**Author:** ![lestat-jin](https://sea2.discourse-cdn.com/flex002/user_avatar/forum.kx.com/lestat-jin/32/128_2.png) [@lestat-jin](https://forum.kx.com/u/lestat-jin)\
**Post date:** [February 9, 2025, 5:03pm UTC](https://forum.kx.com/t/high-dimensional-matrix-index/14135/5 "2025-02-09T17:03:30Z")

</div>

Thanks! maybe time to refresh my memory of the course did some time ago...
